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

export const SelectKecamatan = (props: ReactSelectProps) => {
    const data = useKecamatan();

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

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