import { useEffect } from 'react'; import flatpickr from 'flatpickr'; import 'flatpickr/dist/flatpickr.css'; import Label from './Label'; import { CalenderIcon } from '../../icons'; import Hook = flatpickr.Options.Hook; import DateOption = flatpickr.Options.DateOption; type PropsType = { id: string; mode?: "single" | "multiple" | "range" | "time"; onChange?: Hook | Hook[]; defaultDate?: DateOption; label?: string; placeholder?: string; }; export default function DatePicker({ id, mode, onChange, label, defaultDate, placeholder, }: PropsType) { useEffect(() => { const flatPickr = flatpickr(`#${id}`, { mode: mode || "single", static: true, monthSelectorType: "static", dateFormat: "Y-m-d", defaultDate, onChange, }); return () => { if (!Array.isArray(flatPickr)) { flatPickr.destroy(); } }; }, [mode, onChange, id, defaultDate]); return (