import React from "react";
import SearchableSelect2 from "@/components/ui/SearchableSelect";

interface WithdrawTypeSelectProps<T extends string> {
  withdrawType: { label: string; value: string } | null;
  setWithdrawType: (value: { label: string; value: string } | null) => void;
  clearError: (field: T) => void;
  errors: Partial<Record<T, string>>;
  handleFieldBlur: (
    field: T,
    validateField: (field: T) => string | undefined
  ) => void;
  validateField: (field: T) => string | undefined;
}

const WithdrawTypeSelect = <T extends string>({
  withdrawType,
  setWithdrawType,
  clearError,
  errors,
  handleFieldBlur,
  validateField,
}: WithdrawTypeSelectProps<T>) => {
  return (
    <div className="group transition-all duration-200">
      <SearchableSelect2
        label="Type"
        apiUrl="/api/searchabledropdown/cashwithdrawtype"
        value={withdrawType}
        onChange={(option) => {
          setWithdrawType(option);
          clearError("withdrawType" as T);
        }}
        placeholder="Select withdrawal type..."
        onBlur={() => handleFieldBlur("withdrawType" as T, validateField)}
        error={errors["withdrawType" as T]}
        className="group-hover:border-[#428B4D]/50"
      />
    </div>
  );
};

export default WithdrawTypeSelect;
