import { isEqual } from "lodash";
import { useForm, UseFormReturnType } from "@mantine/form";
import { BoardSchema, StatusSchema } from "@/lib/client";

export type DealsFiltersForm = {
    id: number | null;
    name: string;
    board: BoardSchema | null;
    status: StatusSchema | null;
};

type ReturnType = {
    form: UseFormReturnType<DealsFiltersForm>;
    isChangedFilters: boolean;
};

const useDealsFilters = (): ReturnType => {
    const initialFilters = {
        id: null,
        board: null,
        status: null,
        name: "",
    };

    const form = useForm<DealsFiltersForm>({
        initialValues: initialFilters,
    });

    const isChangedFilters = !isEqual(form.values, initialFilters);

    return {
        form,
        isChangedFilters,
    };
};

export default useDealsFilters;
