import Grid from '@mui/material/Grid';
import { useState } from 'react';
import { useFormContext } from 'react-hook-form';
import { useParams } from 'react-router';
import { Field } from 'src/components/hook-form';

type IdentitasProps = {
  isPengganti: boolean;
  //   disabledTambah: boolean;
  //   disabledHapus: boolean;
};

const Identitas = ({ isPengganti }: IdentitasProps) => {
  const { dnId } = useParams();
  const { setValue } = useFormContext();

  const [jumlahKeterangan, setJumlahKeterangan] = useState<number>(0);

  const maxKeterangan = 5;

  const handleTambah = () => {
    if (jumlahKeterangan < maxKeterangan) {
      setJumlahKeterangan(jumlahKeterangan + 1);
    }
  };

  const handleHapus = () => {
    if (jumlahKeterangan > 0) {
      const newCount = jumlahKeterangan - 1;
      setJumlahKeterangan(newCount);
      // reset value form field yang dihapus
      setValue(`keterangan${newCount + 1}`, null);
    }
  };

  return (
    <Grid container rowSpacing={2} alignItems="center" columnSpacing={2}>
        <Grid size={{ md: 6 }}>
          <Field.DatePicker name="tglPemotongan" label="Tanggal Pemotongan" />
        </Grid>
        <Grid size={{ md: 3 }}>
          <Field.DatePicker name="thnPajak" label="Tahun Pajak" view="year" format="YYYY" />
        </Grid>
        <Grid size={{ md: 3 }}>
          <Field.DatePicker name="msPajak" label="Masa Pajak" view="month" format="MM" />
        </Grid>
      </Grid>
  );
};

export default Identitas;
