import { Controller } from "react-hook-form";
import MuiDatePicker from "@/core/components/MuiDatePicker";
import React from "react";
import moment from "jalali-moment";

const FromDateController = ({ control }) => {
    return (
        <Controller
            name="from_date"
            control={control}
            render={({ field: { onChange, value }, fieldState: { error } }) => (
                <MuiDatePicker
                    name="from_date"
                    error={!!error}
                    value={value}
                    label={'تاریخ تصادف (از تاریخ)'}
                    placeholder={"از تاریخ"}
                    setFieldValue={(name, newValue) => {
                        const formattedDate = moment(new Date(newValue)).locale("en").format("YYYY-MM-DD");
                        onChange(formattedDate); // Update the field value in react-hook-form
                    }}
                    helperText={error ? error.message : null}
                />
            )}
        />
    );
};
export default FromDateController;
