import { Kas, ReactSelectProps } from '@/types';
import { useKas } from '@/useQuery/query';
import { Select } from './Select';

export const SelectKas = (props: ReactSelectProps) => {
    const kas = useKas();

    const OPTION_KAS = kas.data?.map((item: Kas) => ({
        label: `${item.id} : ${item.nama}`,
        value: item.id,
    }));

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