import { useState } from "react";
import { convertToJalali } from "@/helper";
import { ButtonGroup } from "@mui/material";
import PopoverDate from "@/app/component/PopoverDate";

function FilterDate() {
  const [date, setDate] = useState({
    start: null,
    end: null,
  });

  const updateDate = (newDate, type) => {
    setDate({
      ...date,
      [type]: newDate,
    });
  };

  return (
    <ButtonGroup variant="outlined">
      <PopoverDate
        type="start"
        date={date.start}
        updateDate={updateDate}
        text={date.start ? convertToJalali(date.start) : "از تاریخ"}
      />
      <PopoverDate
        type="end"
        date={date.end}
        updateDate={updateDate}
        text={date.end ? convertToJalali(date.end) : "تا تاریخ"}
      />
    </ButtonGroup>
  );
}

export default FilterDate;
