import { ProdukTabungan, ReactSelectProps } from '@/types';
import { useProdukTabungan } from '@/useQuery/query';
import { Select } from './Select';

export const SelectProdukTabungan = (props: ReactSelectProps) => {
    const produk = useProdukTabungan();

    const option_produk = produk.data
        ?.filter((item: ProdukTabungan) => item.status == 1)
        .map((item: ProdukTabungan) => ({
            label: `${item.id} : ${item.nama}`,
            value: item.id,
        }));

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