"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MenuOrganization = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const Button_1 = require("../Button");
const ContentState_1 = require("../ContentState");
const SearchField_1 = require("../SearchField");
const constants_1 = require("./constants");
const MenuOrganizationSkeleton_1 = require("./MenuOrganizationSkeleton");
const NoData_1 = require("./NoData");
const OrganizationButton_1 = require("./OrganizationButton");
const OrganizationList_1 = require("./OrganizationList");
const OrganizationListSkeleton_1 = require("./OrganizationListSkeleton");
const styles_1 = require("./styles");
const useLogic_1 = require("./useLogic");
const MenuOrganization = (props) => {
    const { anchorOrigin = { vertical: 'bottom', horizontal: 'right' }, transformOrigin = { vertical: 'top', horizontal: 'right' }, } = props;
    const { actionButtonProps, hasAction, isLoading, isError, onRetry, isComponentLoading, isShowOrganizationList, searchProps, popoverProps, organizationListProps, organizationButtonProps, isShowSearchField, isMobile, currentOrganization, notSelectedPlaceholder = constants_1.DEFAULT_NOT_SELECTED_PLACEHOLDER, isOpen, onOpen, } = (0, useLogic_1.useLogic)(props);
    if (isComponentLoading) {
        return (0, jsx_runtime_1.jsx)(MenuOrganizationSkeleton_1.MenuOrganizationSkeleton, {});
    }
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [currentOrganization ? ((0, jsx_runtime_1.jsx)(OrganizationButton_1.OrganizationButton, { ...organizationButtonProps, currentOrganization: currentOrganization })) : (notSelectedPlaceholder({ isOpen, onOpen })), (0, jsx_runtime_1.jsxs)(styles_1.StyledPopover, { ...popoverProps, anchorOrigin: anchorOrigin, transformOrigin: transformOrigin, title: constants_1.POPOVER_TITLE, children: [isShowSearchField && ((0, jsx_runtime_1.jsx)(styles_1.SearchWrapper, { children: (0, jsx_runtime_1.jsx)(SearchField_1.SearchField, { fullWidth: true, ...searchProps }) })), (0, jsx_runtime_1.jsx)(styles_1.OrganizationsWrapper, { "$isLoading": isLoading, className: constants_1.menuOrganizationClassnames.root, children: (0, jsx_runtime_1.jsx)(ContentState_1.ContentState, { isLoading: isLoading, isCustom: isError, customState: {
                                title: ((0, jsx_runtime_1.jsx)(styles_1.StyledTypography, { children: "\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C \u0434\u0430\u043D\u043D\u044B\u0435" })),
                                Actions: ((0, jsx_runtime_1.jsx)(Button_1.Button, { variant: "light", color: "grey", onClick: onRetry, children: "\u041F\u043E\u043F\u0440\u043E\u0431\u043E\u0432\u0430\u0442\u044C \u0441\u043D\u043E\u0432\u0430" })),
                                className: constants_1.menuOrganizationClassnames.errorPlaceholder,
                            }, loadingContent: (0, jsx_runtime_1.jsx)(OrganizationListSkeleton_1.OrganizationListSkeleton, {}), children: isShowOrganizationList ? ((0, jsx_runtime_1.jsx)(OrganizationList_1.OrganizationList, { ...organizationListProps })) : ((0, jsx_runtime_1.jsx)(NoData_1.NoData, {})) }) }), hasAction && ((0, jsx_runtime_1.jsx)(styles_1.ActionWrapper, { children: (0, jsx_runtime_1.jsx)(Button_1.Button, { fullWidth: true, ...actionButtonProps, size: isMobile ? 'large' : 'medium', children: actionButtonProps.text }) }))] })] }));
};
exports.MenuOrganization = MenuOrganization;
