import React from "react";
import { Button, Typography, Checkbox, FormControlLabel } from "@mui/material";
import { Grid } from "../../../../../components/grid/Grid";

export const FormActions = ({
  formik,
  onClose,
  showCloseButton,
  isKillHouse,
  onSubmit,
}) => {
  if (showCloseButton) {
    return (
      <Grid item xs={12} mt={4}>
        <Button color="primary" fullWidth variant="contained" onClick={onClose}>
          متوجه شدم
        </Button>
      </Grid>
    );
  }

  // For KillHouse: check if area_activity contains "مرغ"
  const isAreaActivityValid = isKillHouse
    ? formik.values.area_activity && formik.values.area_activity.includes("مرغ")
    : true;

  return (
    <>
      <Grid item xs={12}>
        <FormControlLabel
          control={
            <Checkbox
              checked={formik.values.verify_mobile}
              onChange={formik.handleChange}
              name="verify_mobile"
              color="primary"
            />
          }
          label="احراز شماره موبایل"
        />
      </Grid>
      <Grid item xs={12}>
        <Button
          disabled={
            formik.errors.isAccepted ||
            Boolean(formik.errors.national_id) ||
            !isAreaActivityValid
          }
          color="primary"
          fullWidth
          variant="contained"
          onClick={onSubmit}
          type="button"
        >
          ثبت
        </Button>
        {isKillHouse && !isAreaActivityValid && (
          <Typography
            variant="caption"
            color="error"
            sx={{ mt: 1, display: "block" }}
          >
            رسته واحد صنفی باید شامل کلمه &quot;مرغ&quot; باشد
          </Typography>
        )}
      </Grid>
    </>
  );
};
