import {
  Button,
  FormControl,
  FormControlLabel,
  InputLabel,
  MenuItem,
  Radio,
  RadioGroup,
  Select,
  Switch,
  TextField,
} from "@mui/material";
import { useContext, useState } from "react";
import { useDispatch } from "react-redux";
import { AdvancedTable } from "../../../../components/advanced-table/AdvancedTable";
import { Grid } from "../../../../components/grid/Grid";
import { AppContext } from "../../../../contexts/AppContext";
import { SPACING } from "../../../../data/spacing";
import { provinceMakeKillRequestForPoultryService } from "../../services/province-make-kill-request-for-poultry";
// import PersonAddAlt1Icon from "@mui/icons-material/PersonAddAlt1";
// import DescriptionIcon from "@mui/icons-material/Description";
// import HistoryIcon from "@mui/icons-material/History";
import SettingsIcon from "@mui/icons-material/Settings";
import CircleIcon from "@mui/icons-material/Circle";
import {
  CLOSE_MODAL,
  DRAWER,
  OPEN_MODAL,
} from "../../../../lib/redux/slices/appSlice";

export const ProvinceKillerManagment = () => {
  const dispatch = useDispatch();
  const [openNotif] = useContext(AppContext);
  const hours = Array.from({ length: 8 }, (_, i) => i + 8);
  const [selectedHour, setSelectedHour] = useState("");
  const [isChecked, setIsChecked] = useState(false);
  const [tableRowsdata] = useState([
    [
      "احمد",
      <Switch key={1} checked={false} onClick={() => {}} />,

      <TextField id="input2" label="درصد" key={3} variant="outlined" />,

      <Button
        key={10}
        onClick={() => {
          dispatch(
            DRAWER({
              title: "ثبت اطلاعات جوجه ریزی",
              right: !(window.innerWidth <= 600),
              bottom: window.innerWidth <= 600,
              content: (
                <>
                  <FormControl fullWidth>
                    <InputLabel id="demo-simple-select-label">
                      کشتارکن دارای کشتارگاه است
                    </InputLabel>
                    <Select
                      labelId="demo-simple-select-label"
                      id="simple-select"
                      value={"s"}
                      label="namenamename"
                      // onChange={}
                    >
                      <RadioGroup
                        aria-labelledby="demo-radio-buttons-group-label"
                        defaultValue="female"
                        name="radio-buttons-group"
                      >
                        <FormControlLabel
                          value="yes"
                          control={<Radio />}
                          label="بله"
                        />
                        <FormControlLabel
                          value="no"
                          control={<Radio />}
                          label="خیر"
                        />
                      </RadioGroup>
                    </Select>
                  </FormControl>

                  <FormControl fullWidth>
                    <InputLabel id="demo-simple-select-label">
                      کشتارکن دوم
                    </InputLabel>
                    <Select
                      labelId="demo-simple-select-label"
                      id="simple-select"
                      value={"s"}
                      label="namenamename"
                      // onChange={}
                    >
                      <RadioGroup
                        aria-labelledby="demo-radio-buttons-group-label"
                        defaultValue="female"
                        name="radio-buttons-group"
                      >
                        <FormControlLabel
                          value="yes"
                          control={<Radio />}
                          label="بله"
                        />
                        <FormControlLabel
                          value="no"
                          control={<Radio />}
                          label="خیر"
                        />
                      </RadioGroup>
                    </Select>
                  </FormControl>
                </>
              ),
            })
          );
        }}
        variant="contained"
      >
        <SettingsIcon />
      </Button>,
      "بله",
      "بهار لرستان",

      <CircleIcon key={145} color="success" />,

      // 1234,
      // 1234,
      // 1234,
      // 1234,

      <TextField id="input2" label="سهمیه امروز" key={3} variant="outlined" />,
      <TextField id="input3" label="ضمانت" key={4} variant="outlined" />,

      258,
      <Switch key={111} checked={true} onClick={() => {}} />,

      <Button key={5} variant="contained">
        ارسال
      </Button>,
      // <PersonAddAlt1Icon key={6} />,
      // <DescriptionIcon key={7} />,
      // <HistoryIcon key={8} />,
      <Button
        key={2561}
        onClick={() => {
          dispatch(
            OPEN_MODAL({
              title: "انتخاب کنید",
              content: (
                <Grid container gap={SPACING.SMALL} spacing={4}>
                  <Button color="success" variant="contained">
                    اطلاعات هویتی
                  </Button>
                  <Button color="success" variant="contained">
                    اسناد مالی
                  </Button>
                  <Button color="success" variant="contained">
                    سابقه مالی
                  </Button>
                  <Button
                    variant="outlined"
                    color="error"
                    onClick={() => {
                      dispatch(CLOSE_MODAL());
                    }}
                  >
                    بستن
                  </Button>
                </Grid>
              ),
            })
          );
        }}
      >
        بیشتر
      </Button>,
    ],
  ]);

  return (
    <Grid container mt={SPACING.SMALL}>
      <Grid container width="100%" justifyContent="space-between">
        <Grid>
          <Button
            variant="contained"
            color="primary"
            onClick={() => {
              dispatch(provinceMakeKillRequestForPoultryService()).then((r) => {
                if (r.payload.error) {
                  openNotif({
                    vertical: "top",
                    horizontal: "center",
                    msg: r.payload.error,
                    severity: "error",
                  });
                } else {
                  openNotif({
                    vertical: "top",
                    horizontal: "center",
                    msg: "عملیات با موفقیت انجام شد.",
                    severity: "success",
                  });
                }
              });
            }}
          >
            ارسال درخواست
          </Button>
        </Grid>
        <Grid container gap={2}>
          <FormControlLabel
            control={
              <Switch
                checked={isChecked}
                onChange={() => setIsChecked(!isChecked)}
              />
            }
            label="محدودیت زمان درخواست کشتار"
            labelPlacement="start"
          />
          {isChecked && (
            <FormControl style={{ width: 200 }}>
              <InputLabel id="hour-label">ساعت پایان درخواست</InputLabel>
              <Select
                labelId="hour-label"
                label="ساعت پایان درخواست"
                id="hour-select"
                value={selectedHour}
                onChange={(event) => setSelectedHour(event.target.value)}
              >
                {hours.map((hour) => (
                  <MenuItem key={hour} value={hour}>
                    {hour}:00
                  </MenuItem>
                ))}
              </Select>
            </FormControl>
          )}
        </Grid>
      </Grid>
      <AdvancedTable
        name={"مدیریت کشتارکن"}
        data={tableRowsdata}
        columns={[
          "کشتارکن",
          "وضعیت",
          "درصد سهمیه",
          "مدیریت کشتارگاه",
          "دارای کشتارگاه",
          "نام کشتارگاه",
          "دریافتی",
          // "دریافتی 3.4",
          // "دریافتی 3.3",
          // "دریافتی 3.2",
          // "دریافتی 3.1",
          "سهمیه امروزی",
          "ضمانت",
          "مانده از ضمانت",
          "فیلتر تسویه",
          "درخواست کشتار",
          // "اطلاعات هویتی",
          // "اسناد مالی",
          // "سابقه",
          "بیشتر",
        ]}
      />
    </Grid>
  );
};
