import { Button } from "@mui/material";
import { Grid } from "../../../../components/grid/Grid";
import { SPACING } from "../../../../data/spacing";
import { useDispatch } from "react-redux";
import { provinceUnarchiveFeeService } from "../../services/province-unarchive-fee";
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
import { CLOSE_MODAL } from "../../../../lib/redux/slices/appSlice";
import { AppContext } from "../../../../contexts/AppContext";
import { useContext } from "react";

export const ProvinceUnarchiveFee = ({
  provinceKillRequestKey,
  updateTable,
}) => {
  const dispatch = useDispatch();
  const [openNotif] = useContext(AppContext);

  return (
    <Grid>
      <Grid container gap={SPACING.TINY} width="100%">
        <Button
          variant="contained"
          onClick={() => {
            dispatch(
              provinceUnarchiveFeeService({
                role: getRoleFromUrl(),
                type: "return_archive",
                province_kill_request_key: provinceKillRequestKey,
                // return_archive_message: "fesfewfwwewf",
              })
            ).then((r) => {
              updateTable();
              dispatch(CLOSE_MODAL());
              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>
        <Button
          variant="outlined"
          onClick={() => {
            dispatch(CLOSE_MODAL());
          }}
        >
          خیر
        </Button>
      </Grid>
    </Grid>
  );
};
