import { Bank, ReactSelectProps } from '@/types';
import { useBank } from '@/useQuery/query';
import { Select } from './Select';

export const SelectBank = (props: ReactSelectProps) => {
    const banks = useBank();

    const option_bank = banks.data?.map((item: Bank) => ({
        label: `${item.id} : ${item.nama}`,
        value: item.id,
    }));

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