import { FormField, FormItem } from "@repo/shadcn-ui/components";

import { Control, FieldPath, FieldValues } from "react-hook-form";
import { CustomerModalSelector } from "./customer-modal-selector";

type CustomerModalSelectorFieldProps<TFormValues extends FieldValues> = {
  control: Control<TFormValues>;
  name: FieldPath<TFormValues>;
  disabled?: boolean;
  required?: boolean;
  readOnly?: boolean;
  className?: string;
};

export function CustomerModalSelectorField<TFormValues extends FieldValues>({
  control,
  name,
  disabled = false,
  required = false,
  readOnly = false,
  className,
}: CustomerModalSelectorFieldProps<TFormValues>) {
  const isDisabled = disabled;
  const isReadOnly = readOnly && !disabled;

  return (
    <FormField
      control={control}
      name={name}
      render={({ field }) => {
        const { name, value, onChange, onBlur, ref } = field;
        console.log({ name, value, onChange, onBlur, ref });
        return (
          <FormItem className={className}>
            <CustomerModalSelector value={value} onValueChange={onChange} />
          </FormItem>
        );
      }}
    />
  );
}
