<commit_before>// @flow
import React from "react"
import { makeStyles } from "@material-ui/styles"
import Grid from "@material-ui/core/Grid"
import List from "@material-ui/core/List"
import ListItem from "@material-ui/core/ListItem"
import Checkbox from "@material-ui/core/Checkbox"
import Hidden from "@material-ui/core/Hidden"
import IconButton from "@material-ui/core/IconButton"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import AddToCartButton from "./AddToCartButton"
import StrainCatalogListHeader from "components/Stocks/Catalogs/Strains/StrainCatalogListHeader"
import PlasmidCatalogListHeader from "components/Stocks/Catalogs/Plasmids/PlasmidCatalogListHeader"
import useCheckboxes from "hooks/useCheckboxes"
import { useCatalogStore } from "components/Stocks/Catalogs/common/CatalogContext"

const useStyles = makeStyles({
  listHeaders: {
    borderBottom: "1px solid #888",
    backgroundColor: "#f6f9fc",
    color: "#525f7f",
    fontWeight: 600,
  },
  list: {
    padding: 0,
  },
  button: {
    color: "#004080",
  },
})

type Props = {
  /** Type of stock (strain or plasmid) */
  stockType: string,
}

/**
 * CatalogListHeader contains the list of headers (i.e.
 * descriptor, summary, etc) at the top of the catalog page.
 */

const CatalogListHeader = ({ stockType }: Props) => {
  const [{ checkedItems }] = useCatalogStore()
  const { resetCheckedItems, handleCheckAllChange } = useCheckboxes({})
  const classes = useStyles()
  const checkedItemsLength = checkedItems.length

  let content =
    stockType === "strain" ? (
      <StrainCatalogListHeader />
    ) : (
      <PlasmidCatalogListHeader />
    )

  if (checkedItemsLength > 0) {
    content = (
      <>
        {checkedItemsLength} items selected
        <AddToCartButton
          data={checkedItems}
          setCheckedItems={resetCheckedItems}
          stockType={stockType}
        />
        <IconButton
          size="medium"
          className={classes.button}
          onClick={() => {}}
          title="Download PDF"
          aria-label="Download PDF">
          <FontAwesomeIcon icon="download" />
        </IconButton>
      </>
    )
  }

  return (
    <List className={classes.list}>
      <ListItem className={classes.listHeaders}>
        <Grid container spacing={0} alignItems="center">
          <Hidden smDown>
            <Grid item md={1}>
              {checkedItemsLength > 0 && (
                <Checkbox
                  indeterminate={checkedItemsLength > 0 ? true : false}
                  color="default"
                  value="selectAll"
                  onChange={handleCheckAllChange}
                  inputProps={{
                    "aria-label": "checkbox select all",
                  }}
                />
              )}
            </Grid>
          </Hidden>
          {content}
        </Grid>
      </ListItem><commit_msg>feat: don't display cart button in catalog list header if more than 12 items selected<commit_after>// @flow
import React from "react"
import { makeStyles } from "@material-ui/styles"
import Grid from "@material-ui/core/Grid"
import List from "@material-ui/core/List"
import ListItem from "@material-ui/core/ListItem"
import Checkbox from "@material-ui/core/Checkbox"
import Hidden from "@material-ui/core/Hidden"
import IconButton from "@material-ui/core/IconButton"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import AddToCartButton from "./AddToCartButton"
import StrainCatalogListHeader from "components/Stocks/Catalogs/Strains/StrainCatalogListHeader"
import PlasmidCatalogListHeader from "components/Stocks/Catalogs/Plasmids/PlasmidCatalogListHeader"
import useCheckboxes from "hooks/useCheckboxes"
import { useCatalogStore } from "components/Stocks/Catalogs/common/CatalogContext"

const useStyles = makeStyles({
  listHeaders: {
    borderBottom: "1px solid #888",
    backgroundColor: "#f6f9fc",
    color: "#525f7f",
    fontWeight: 600,
  },
  list: {
    padding: 0,
  },
  button: {
    color: "#004080",
  },
})

type Props = {
  /** Type of stock (strain or plasmid) */
  stockType: string,
}

/**
 * CatalogListHeader contains the list of headers (i.e.
 * descriptor, summary, etc) at the top of the catalog page.
 */

const CatalogListHeader = ({ stockType }: Props) => {
  const [{ checkedItems }] = useCatalogStore()
  const { resetCheckedItems, handleCheckAllChange } = useCheckboxes({})
  const classes = useStyles()
  const checkedItemsLength = checkedItems.length

  let content =
    stockType === "strain" ? (
      <StrainCatalogListHeader />
    ) : (
      <PlasmidCatalogListHeader />
    )

  if (checkedItemsLength > 0) {
    content = (
      <>
        {checkedItemsLength} items selected
        {checkedItemsLength <= 12 && (
          <AddToCartButton
            data={checkedItems}
            setCheckedItems={resetCheckedItems}
          />
        )}
        <IconButton
          size="medium"
          className={classes.button}
          onClick={() => {}}
          title="Download PDF"
          aria-label="Download PDF">
          <FontAwesomeIcon icon="download" />
        </IconButton>
      </>
    )
  }

  return (
    <List className={classes.list}>
      <ListItem className={classes.listHeaders}>
        <Grid container spacing={0} alignItems="center">
          <Hidden smDown>
            <Grid item md={1}>
              {checkedItemsLength > 0 && (
                <Checkbox
                  indeterminate={true}
                  color="default"
                  value="selectAll"
                  onChange={handleCheckAllChange}
                  inputProps={{
                    "aria-label": "checkbox select all",
                  }}
                />
              )}
            </Grid>
          </Hidden>
          {content}
        </Grid>
      </ListItem>
{'fraction_non_alphanumeric': 0.11664101248503506, 'fraction_numerical': 0.009064477509834103, 'mean_word_length': 2.472684085510689, 'pattern_counts': {'":': 2, '<': 40, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2140064', 'n_tokens_mistral': 1694, 'n_tokens_neox': 1644, 'n_words': 379}