"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OptionsModal = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const Button_1 = require("../../Button");
const Dialog_1 = require("../../Dialog");
const DialogActions_1 = require("../../DialogActions");
const Paper_1 = require("../../Paper");
const SearchField_1 = require("../../SearchField");
const Tree_1 = require("../../Tree");
const ErrorMessage_1 = require("./ErrorMessage");
const Loader_1 = require("./Loader");
const NoData_1 = require("./NoData");
const styles_1 = require("./styles");
const useLogic_1 = require("./useLogic");
const OptionsModal = (props) => {
    const { isNoResult, searchFieldProps, modalProps, treeListProps, cancelButtonProps, confirmButtonProps, } = (0, useLogic_1.useLogic)(props);
    const { isOpen, initialValue, options, isLoading, isLoadingError, loadingErrorMsg, treeProps, filterOptions, onChange, onRetry, onClose, ...externalDialogProps } = props;
    const renderComponent = () => {
        if (isLoading) {
            return (0, jsx_runtime_1.jsx)(Loader_1.Loader, {});
        }
        if (isLoadingError) {
            return ((0, jsx_runtime_1.jsx)(ErrorMessage_1.ErrorMessage, { loadingErrorMsg: loadingErrorMsg, onRetry: onRetry }));
        }
        if (isNoResult) {
            return (0, jsx_runtime_1.jsx)(NoData_1.NoData, {});
        }
        return (0, jsx_runtime_1.jsx)(Tree_1.TreeList, { ...treeProps, ...treeListProps });
    };
    return ((0, jsx_runtime_1.jsxs)(Dialog_1.Dialog, { ...externalDialogProps, disableRestoreFocus: true, open: isOpen, ...modalProps, children: [(0, jsx_runtime_1.jsxs)(styles_1.StyledDialogContent, { "$size": modalProps.size, children: [(0, jsx_runtime_1.jsx)(SearchField_1.SearchField, { fullWidth: true, ...searchFieldProps }), (0, jsx_runtime_1.jsx)(Paper_1.Paper, { variant: "outlined", children: (0, jsx_runtime_1.jsx)(styles_1.TreeListWrapper, { children: renderComponent() }) })] }), (0, jsx_runtime_1.jsxs)(DialogActions_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(Button_1.Button, { variant: "text", ...cancelButtonProps, children: "\u041E\u0442\u043C\u0435\u043D\u0430" }), (0, jsx_runtime_1.jsx)(Button_1.Button, { ...confirmButtonProps, children: "\u0412\u044B\u0431\u0440\u0430\u0442\u044C" })] })] }));
};
exports.OptionsModal = OptionsModal;
