text: import React from "react";
  import store from "data/store"
  import axios from "axios";
  import { useCookies } from 'react-cookie';
  import { useHistory } from "react-router-dom";
  
  import IconButton from "@material-ui/core/IconButton";
  import Tooltip from "@material-ui/core/Tooltip";
  import CompareArrowsIcon from "@material-ui/icons/CompareArrows";
  import IndeterminateCheckBoxIcon from "@material-ui/icons/IndeterminateCheckBox";
  import DeleteIcon from '@material-ui/icons/Delete';
  import { withStyles } from "@material-ui/core/styles";
  import Modal from "./TransferModal";
  
  const defaultToolbarSelectStyles = {
      iconButton: {
      },
      iconContainer: {
          marginRight: "24px",
      },
      inverseIcon: {
          transform: "rotate(90deg)",
      },
  };
  function CustomToolbarSelect(props) {
      const [cookies, setCookie] = useCookies();
      let history = useHistory();
      const handleClickInverseSelection = () => {
          const nextSelectedRows = props.displayData.reduce((nextSelectedRows, _, index) => {
              if (!props.selectedRows.data.find(selectedRow => selectedRow.index === index)) {
                  nextSelectedRows.push(index);
              }
              return nextSelectedRows;
          }, []);
          props.setSelectedRows(nextSelectedRows);
      };
      const handleClickDeselectAll = () => {
          props.setSelectedRows([]);
      };
  
      const deleteList = () => {
          var idList = []
          props.selectedArray.forEach(e => {
              idList.push(props.data[e].id)
          });
          const headers = {
              'Authorization': 'Bearer ' + cookies.token
          };
          var jsonData = {}
          jsonData.idList = String(idList)
          jsonData.companyId = cookies.companyId
          axios.post(store.webApiUrl + 'User/DeleteList/', jsonData, { headers })
              .then(r => {
                  if (r.status == "200") {
                      window.location.reload()
                      alert('刪除成功')
                      window.location.reload(false);
                      return true;
                  }
                  else {
                      alert('刪除失敗')
                      return false
                  }
              }
              );
      }
      const { classes } = props;
      return (
          <>
              <div className={classes.iconContainer}>
                  <Tooltip title={"DeleteAll"}>
                      <IconButton className={classes.iconButton} onClick={deleteList} >
                          <DeleteIcon className={classes.icon} />
                      </IconButton>
                  </Tooltip>
                  <Tooltip title={"Deselect ALL"}>
                      <IconButton className={classes.iconButton} onClick={handleClickDeselectAll}>
                          <IndeterminateCheckBoxIcon className={classes.icon} />
                      </IconButton>
                  </Tooltip>
                  <Tooltip title={"Inverse selection"}>
                      <IconButton className={classes.iconButton} onClick={handleClickInverseSelection}>
                          <CompareArrowsIcon className={[classes.icon, classes.inverseIcon].join(" ")} />
                      </IconButton>
                  </Tooltip>
                  <div>
                      <Modal selectedArray={props.selectedArray} data={props.data} ></Modal>
                  </div>
              </div>
          </>
      );
  }
  export default withStyles(defaultToolbarSelectStyles, { name: "CustomToolbarSelect" })(CustomToolbarSelect);