"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const hooks_1 = require("./hooks");
const useLogic = ({ form, onSubmit, validationSchema, searchField, mainFilters, quickFilters, secondaryFilters, submitButton, mainFiltersColumns, isLoading, }) => {
    const [isModalOpen, setIsModalOpen] = (0, react_1.useState)(false);
    const [defaultValues, setDefaultValues] = (0, react_1.useState)({});
    const isFirstMountAfterLoading = (0, hooks_1.useFirstMountAfterLoading)(isLoading);
    (0, react_1.useEffect)(() => {
        if (isFirstMountAfterLoading) {
            setDefaultValues(form.getValues());
        }
    }, [form]);
    const onOpenModal = () => {
        setIsModalOpen(true);
    };
    // Функция отправки формы на кнопку "Применить" в модальном окне
    const onSubmitModal = (submittedValues) => {
        form.reset(submittedValues);
    };
    const dialogProps = {
        validationSchema,
        form,
        mainFilters,
        quickFilters,
        secondaryFilters,
        onSubmit: onSubmitModal,
        isModalOpen,
        setIsModalOpen,
        defaultValues,
    };
    return {
        form,
        onSubmit,
        searchField,
        mainFilters,
        quickFilters,
        secondaryFilters,
        submitButton,
        onOpenModal,
        dialogProps,
        mainFiltersColumns,
        isLoading,
    };
};
exports.useLogic = useLogic;
