import ObjectSelect from "@/components/selects/ObjectSelect/ObjectSelect";
import useAttributeOptionsList from "@/hooks/lists/useAttributeOptionsList";
import { AttrOptionSchema } from "@/lib/client";

type Props = {
    value?: AttrOptionSchema | null;
    onChange: (val: AttrOptionSchema | null) => void;
    selectId: number;
    error?: string;
    label?: string;
};

const DefaultAttrOptionSelect = ({ selectId, ...props }: Props) => {
    const { options } = useAttributeOptionsList({ selectId });

    return (
        <ObjectSelect
            label={"Значение"}
            {...props}
            data={options}
            onClear={() => props.onChange(null)}
            getLabelFn={(option: AttrOptionSchema) => option.label}
            clearable
            searchable
        />
    );
};

export default DefaultAttrOptionSelect;
