import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Button } from '../../Button';
import { Dialog } from '../../Dialog';
import { DialogActions } from '../../DialogActions';
import { Paper } from '../../Paper';
import { SearchField } from '../../SearchField';
import { TreeLikeList } from '../../TreeLikeList';
import { ErrorMessage } from './ErrorMessage';
import { Loader } from './Loader';
import { NoData } from './NoData';
import { StyledDialogContent, TreeListWrapper } from './styles';
import { useLogic } from './useLogic';
export const OptionsModal = (props) => {
    const { isNoResult, searchFieldProps, modalProps, treeLikeListProps, cancelButtonProps, confirmButtonProps, } = useLogic(props);
    const { isOpen, initialValue, options, isConfirmChildrenSelection, isLoading, isLoadingError, loadingErrorMsg, treeProps, filterOptions, onChange, onRetry, onClose, ...externalDialogProps } = props;
    const renderComponent = () => {
        if (isLoading) {
            return _jsx(Loader, {});
        }
        if (isLoadingError) {
            return (_jsx(ErrorMessage, { loadingErrorMsg: loadingErrorMsg, onRetry: onRetry }));
        }
        if (isNoResult) {
            return _jsx(NoData, {});
        }
        return (_jsx(TreeLikeList, { isConfirmChildrenSelection: isConfirmChildrenSelection, ...treeProps, ...treeLikeListProps }));
    };
    return (_jsxs(Dialog, { ...externalDialogProps, disableRestoreFocus: true, open: isOpen, ...modalProps, children: [_jsxs(StyledDialogContent, { "$size": modalProps.size, children: [_jsx(SearchField, { fullWidth: true, ...searchFieldProps }), _jsx(Paper, { variant: "outlined", children: _jsx(TreeListWrapper, { children: renderComponent() }) })] }), _jsxs(DialogActions, { children: [_jsx(Button, { variant: "text", ...cancelButtonProps, children: "\u041E\u0442\u043C\u0435\u043D\u0430" }), _jsx(Button, { ...confirmButtonProps, children: "\u0412\u044B\u0431\u0440\u0430\u0442\u044C" })] })] }));
};
