"use client";

import { FC } from "react";
import ObjectSelect, {
    ObjectSelectProps,
} from "@/components/selects/ObjectSelect/ObjectSelect";
import useBoardsList from "@/hooks/lists/useBoardsList";
import { BoardSchema } from "@/lib/client";

type Props = Omit<
    ObjectSelectProps<BoardSchema | null>,
    "data" | "getLabelFn" | "getValueFn"
> & {
    projectId?: number;
};

const BoardSelect: FC<Props> = ({ projectId, ...props }) => {
    const onClear = () => props.onChange(null);

    const { boards } = useBoardsList({ projectId });

    return (
        <ObjectSelect
            data={boards}
            searchable
            placeholder={"Выберите доску"}
            onClear={onClear}
            {...props}
        />
    );
};

export default BoardSelect;
