import { ReactSelectProps, Role } from '@/types';
import { useRole } from '@/useQuery/query';
import { Select } from './Select';

export const SelectRole = (props: ReactSelectProps) => {
    const roles = useRole();

    const option_role = roles.data?.map((item: Role) => ({
        label: `${item.id} : ${item.nama}`,
        value: item.id,
    }));

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