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

export const SelectKelurahan = (props: ReactSelectProps) => {
    const penempatan = useKelurahan();

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

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