import { useEffect, useRef } from "react"; import { useController } from "react-hook-form"; const DatePicker = ({ name, control, placeholder = "DD-MM-YYYY", className = "", allowText = false, maxDate=new Date(), minDate, ...rest }) => { const inputRef = useRef(null); const { field: { onChange, value, ref } } = useController({ name, control }); useEffect(() => { if (inputRef.current) { flatpickr(inputRef.current, { dateFormat: "d-m-Y", allowInput: allowText, defaultDate: value ? flatpickr.parseDate(value, "Y-m-d") : null, maxDate:maxDate, minDate:new Date(minDate?.split("T")[0]) ?? undefined, onChange: function (selectedDates, dateStr) { onChange(dateStr); }, ...rest }); } }, [inputRef]); return (