import { PenempatanBank, ReactSelectProps } from '@/types';
import { usePenempatanBank } from '@/useQuery/query';
import { Select } from './Select';

export const SelectRekeningBank = (props: ReactSelectProps) => {
    const penempatan = usePenempatanBank();

    const option_bank = penempatan.data?.map((item: PenempatanBank) => ({
        label: `${item.rekening} : ${item.nama}`,
        value: item.rekening,
    }));

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