"use client";

import React from "react";
import { Box, Typography } from "@mui/material";
import MuiDatePicker from "@/core/components/DataTable/filter/fieldsType/CustomDate/MuiDatePicker";

function CustomDatePickerRange({
  column,
  filterParameters,
  defaultFilterTranslation,
  handleChange,
  errors,
}) {
  return (
    <Box sx={{ display: "flex", gap: 1 }}>
      <MuiDatePicker
        label={column.header}
        name={`${column.id}.value[0]`}
        value={filterParameters.value[0]}
        setFieldValue={(name, formattedDate) => {
          handleChange({
            ...filterParameters,
            value: [formattedDate, filterParameters.value[1]],
          });
        }}
        maxDate={filterParameters.value[1]}
        placeholder={`از تاریخ`}
        helperText={
          <Typography
            variant="button"
            sx={{ color: (theme) => theme.palette.primary.main }}
          >
            نوع فیلتر: {defaultFilterTranslation} (تاریخ)
          </Typography>
        }
      />
      <MuiDatePicker
        label={column.header}
        name={`${column.id}.value[1]`}
        value={filterParameters.value[1]}
        setFieldValue={(name, formattedDate) => {
          handleChange({
            ...filterParameters,
            value: [filterParameters.value[0], formattedDate],
          });
        }}
        minDate={filterParameters.value[0]}
        placeholder={`تا تاریخ`}
        helperText={
          errors?.[`${column.id}`]?.value
            ? errors?.[`${column.id}`]?.value.message
            : null
        }
        error={Boolean(errors?.[`${column.id}`]?.value)}
      />
    </Box>
  );
}

export default CustomDatePickerRange;
