import { ReactSelectProps } from '@/types';
import { useKabupaten } from '@/useQuery/query';
import { Select } from './Select';

export const SelectKabupaten = (props: ReactSelectProps) => {
    const data = useKabupaten();

    const option = data.data?.map((item: { kabupaten: string }) => ({
        label: item.kabupaten,
        value: item.kabupaten,
    }));

    return (
        <Select
            value={option?.find((item: { label: string; value: string }) => item.value == props.value) ?? ''}
            isDisabled={props.disable}
            options={option}
            placeholder="Pilih Kota / Kabupaten"
            onChange={(newValue: unknown) => {
                const option = newValue as { label: string; value: string };
                props.onChange?.(option?.value);
            }}
        />
    );
};
