
import { Control, Controller, FieldPath, FieldValues } from "react-hook-form";
import { DatePickerInputComp, SUICalendarProps } from "./date-picker-input-comp.tsx";

type DatePickerInputFieldProps<TFormValues extends FieldValues> = SUICalendarProps & {
  control: Control<TFormValues>;
  name: FieldPath<TFormValues>;

  label?: string;
  placeholder?: string;
  description?: string;

  disabled?: boolean;
  required?: boolean;
  readOnly?: boolean;

  displayDateFormat?: string; // e.g. "dd-MM-yyyy"
  parseDateFormat?: string; // e.g. "yyyy-MM-dd"
  orientation?: "vertical" | "horizontal" | "responsive",
};

export function DatePickerInputField<TFormValues extends FieldValues>({
  control,
  name,
  displayDateFormat = "dd-MM-yyyy",
  parseDateFormat = "yyyy-MM-dd",
  ...props
}: DatePickerInputFieldProps<TFormValues>) {
  return (
    <Controller
      control={control}
      name={name}
      render={({ field, fieldState, formState }) => (
        <DatePickerInputComp
          field={field}
          fieldState={fieldState}
          formState={formState}

          displayDateFormat={displayDateFormat}
          parseDateFormat={parseDateFormat}
          {...props}
        />
      )}
    />
  );
}
