"use strict";
var __webpack_modules__ = {
    "../../application/Plugin": function(module) {
        module.exports = require("../../application/Plugin.js");
    },
    "../../": function(module) {
        module.exports = require("../../index.js");
    },
    "../../variables": function(module) {
        module.exports = require("../../variables/index.js");
    },
    "./AdminContent": function(module) {
        module.exports = require("./AdminContent.js");
    },
    "./AdminTabs": function(module) {
        module.exports = require("./AdminTabs.js");
    },
    "./NoticeArea": function(module) {
        module.exports = require("./NoticeArea.js");
    },
    "./style?6351": function(module) {
        module.exports = require("./style.js");
    },
    antd: function(module) {
        module.exports = require("antd");
    },
    react: function(module) {
        module.exports = require("react");
    },
    "react-router-dom": function(module) {
        module.exports = require("react-router-dom");
    },
    "react/jsx-runtime": function(module) {
        module.exports = require("react/jsx-runtime");
    }
};
var __webpack_module_cache__ = {};
function __webpack_require__(moduleId) {
    var cachedModule = __webpack_module_cache__[moduleId];
    if (void 0 !== cachedModule) return cachedModule.exports;
    var module = __webpack_module_cache__[moduleId] = {
        exports: {}
    };
    __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
    return module.exports;
}
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    AdminLayout: function() {
        return AdminLayout;
    },
    AdminLayoutPlugin: function() {
        return AdminLayoutPlugin;
    },
    AdminProvider: function() {
        return AdminProvider;
    },
    InternalAdminLayout: function() {
        return InternalAdminLayout;
    },
    MenuEditor: function() {
        return MenuEditor;
    }
});
var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("react/jsx-runtime");
var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("react");
var antd__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("antd");
var react_router_dom__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("react-router-dom");
var ___WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("../../");
var _application_Plugin__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("../../application/Plugin");
var _variables__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__("../../variables");
var _AdminContent__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__("./AdminContent");
var _AdminTabs__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__("./AdminTabs");
var _NoticeArea__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__("./NoticeArea");
var _style__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__("./style?6351");
var __WEBPACK_REEXPORT_OBJECT__ = {};
for(var __WEBPACK_IMPORT_KEY__ in _NoticeArea__WEBPACK_IMPORTED_MODULE_9__)if ([
    "AdminProvider",
    "default",
    "MenuEditor",
    "InternalAdminLayout",
    "AdminLayout",
    "AdminLayoutPlugin"
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
    return _NoticeArea__WEBPACK_IMPORTED_MODULE_9__[key];
}).bind(0, __WEBPACK_IMPORT_KEY__);
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
const filterByACL = (schema, options)=>{
    const { allowAll, allowMenuItemIds = [] } = options;
    if (allowAll) return schema;
    const filterSchema = (s)=>{
        if (!s) return;
        for(const key in s.properties)if (Object.prototype.hasOwnProperty.call(s.properties, key)) {
            const element = s.properties[key];
            if (element['x-uid'] && !allowMenuItemIds.includes(element['x-uid'])) delete s.properties[key];
            if (element['x-uid']) filterSchema(element);
        }
    };
    filterSchema(schema);
    return schema;
};
const SchemaIdContext = /*#__PURE__*/ (0, react__WEBPACK_IMPORTED_MODULE_1__.createContext)(null);
SchemaIdContext.displayName = 'SchemaIdContext';
const useMenuProps = ()=>{
    const defaultSelectedUid = (0, react__WEBPACK_IMPORTED_MODULE_1__.useContext)(SchemaIdContext);
    return {
        selectedUid: defaultSelectedUid,
        defaultSelectedUid
    };
};
const MenuEditor = (props)=>{
    const { setTitle } = (0, ___WEBPACK_IMPORTED_MODULE_4__.useDocumentTitle)();
    const navigate = (0, react_router_dom__WEBPACK_IMPORTED_MODULE_3__.useNavigate)();
    const params = (0, react_router_dom__WEBPACK_IMPORTED_MODULE_3__.useParams)();
    const location1 = (0, react_router_dom__WEBPACK_IMPORTED_MODULE_3__.useLocation)();
    const isMatchAdmin = (0, react_router_dom__WEBPACK_IMPORTED_MODULE_3__.useMatch)('/admin');
    const isMatchAdminName = (0, react_router_dom__WEBPACK_IMPORTED_MODULE_3__.useMatch)('/admin/:name');
    const defaultSelectedUid = params.name;
    const { sideMenuRef } = props;
    const ctx = (0, ___WEBPACK_IMPORTED_MODULE_4__.useACLRoleContext)();
    const [current, setCurrent] = (0, react__WEBPACK_IMPORTED_MODULE_1__.useState)(null);
    const onSelect = (param)=>{
        let { item } = param;
        const schema = item.props.schema;
        setTitle(schema.title);
        setCurrent(schema);
        navigate("/admin/".concat(schema['x-uid']));
    };
    const adminSchemaUid = (0, ___WEBPACK_IMPORTED_MODULE_4__.useAdminSchemaUid)();
    const { data, loading } = (0, ___WEBPACK_IMPORTED_MODULE_4__.useRequest)({
        url: "/uiSchemas:getJsonSchema/".concat(adminSchemaUid)
    }, {
        refreshDeps: [
            adminSchemaUid
        ],
        onSuccess (data) {
            const schema = filterByACL(null == data ? void 0 : data.data, ctx);
            if (isMatchAdmin) {
                const s = (0, ___WEBPACK_IMPORTED_MODULE_4__.findMenuItem)(schema);
                if (s) {
                    navigate("/admin/".concat(s['x-uid']));
                    setTitle(s.title);
                } else navigate("/admin/");
                return;
            }
            if (!isMatchAdminName) return;
            const s = (0, ___WEBPACK_IMPORTED_MODULE_4__.findByUid)(schema, defaultSelectedUid);
            if (s) setTitle(s.title);
            else {
                const s = (0, ___WEBPACK_IMPORTED_MODULE_4__.findMenuItem)(schema);
                if (s) {
                    navigate("/admin/".concat(s['x-uid']));
                    setTitle(s.title);
                } else navigate("/admin/");
            }
        }
    });
    const match = (0, react_router_dom__WEBPACK_IMPORTED_MODULE_3__.useMatch)('/admin/:name');
    (0, react__WEBPACK_IMPORTED_MODULE_1__.useEffect)(()=>{
        if (match) {
            const schema = filterByACL(null == data ? void 0 : data.data, ctx);
            const s = (0, ___WEBPACK_IMPORTED_MODULE_4__.findByUid)(schema, defaultSelectedUid);
            if (s) setTitle(s.title);
        }
    }, [
        null == data ? void 0 : data.data,
        location1.pathname,
        defaultSelectedUid
    ]);
    (0, react__WEBPACK_IMPORTED_MODULE_1__.useEffect)(()=>{
        var _Object_values_shift, _current_root, _data_data;
        const properties = (null === (_Object_values_shift = Object.values((null == current ? void 0 : null === (_current_root = current.root) || void 0 === _current_root ? void 0 : _current_root.properties) || {}).shift()) || void 0 === _Object_values_shift ? void 0 : _Object_values_shift['properties']) || (null == data ? void 0 : null === (_data_data = data.data) || void 0 === _data_data ? void 0 : _data_data.properties);
        if (null == sideMenuRef ? void 0 : sideMenuRef.current) {
            const pageType = properties && Object.values(properties).find((item)=>item['x-uid'] === params.name && 'Menu.Item' === item['x-component']);
            const isSettingPage = null == location1 ? void 0 : location1.pathname.includes('/settings');
            if (pageType || isSettingPage) sideMenuRef.current.style.display = 'none';
            else sideMenuRef.current.style.display = 'block';
        }
    }, [
        null == data ? void 0 : data.data,
        params.name,
        sideMenuRef
    ]);
    const schema = (0, react__WEBPACK_IMPORTED_MODULE_1__.useMemo)(()=>{
        const s = filterByACL(null == data ? void 0 : data.data, ctx);
        if (null == s ? void 0 : s['x-component-props']) s['x-component-props']['useProps'] = useMenuProps;
        return s;
    }, [
        null == data ? void 0 : data.data
    ]);
    if (loading) return;
    return /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(SchemaIdContext.Provider, {
        value: defaultSelectedUid,
        children: /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(___WEBPACK_IMPORTED_MODULE_4__.SchemaComponent, {
            memoized: true,
            scope: {
                useMenuProps,
                onSelect,
                sideMenuRef,
                defaultSelectedUid
            },
            schema: schema
        })
    });
};
const InternalAdminLayout = (props)=>{
    var _result_data_data_logo, _result_data_data, _result_data, _result_data_data1, _result_data1;
    const sideMenuRef = (0, react__WEBPACK_IMPORTED_MODULE_1__.useRef)();
    const result = (0, ___WEBPACK_IMPORTED_MODULE_4__.useSystemSettings)();
    const app = (0, ___WEBPACK_IMPORTED_MODULE_4__.useApp)();
    const params = (0, react_router_dom__WEBPACK_IMPORTED_MODULE_3__.useParams)();
    const { styles } = (0, _style__WEBPACK_IMPORTED_MODULE_10__.useStyles)();
    return /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(antd__WEBPACK_IMPORTED_MODULE_2__.Layout, {
        className: styles.layout,
        children: [
            /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(antd__WEBPACK_IMPORTED_MODULE_2__.Layout.Header, {
                className: styles.header,
                children: /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                    className: styles.headerA,
                    children: [
                        /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                            className: styles.headerB,
                            children: [
                                /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                                    className: styles.titleContainer,
                                    onClick: ()=>{
                                        location.href = app.adminUrl;
                                    },
                                    children: [
                                        /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("img", {
                                            className: styles.logo,
                                            src: null == result ? void 0 : null === (_result_data = result.data) || void 0 === _result_data ? void 0 : null === (_result_data_data = _result_data.data) || void 0 === _result_data_data ? void 0 : null === (_result_data_data_logo = _result_data_data.logo) || void 0 === _result_data_data_logo ? void 0 : _result_data_data_logo.url
                                        }),
                                        /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("h1", {
                                            className: styles.title,
                                            children: null == result ? void 0 : null === (_result_data1 = result.data) || void 0 === _result_data1 ? void 0 : null === (_result_data_data1 = _result_data1.data) || void 0 === _result_data_data1 ? void 0 : _result_data_data1.title
                                        })
                                    ]
                                }),
                                /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(MenuEditor, {
                                    sideMenuRef: sideMenuRef
                                }),
                                /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", {
                                    className: styles.editor,
                                    children: /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_AdminTabs__WEBPACK_IMPORTED_MODULE_8__.AdminTabs, {})
                                })
                            ]
                        }),
                        /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                            className: styles.right,
                            children: [
                                /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(___WEBPACK_IMPORTED_MODULE_4__.PinnedPluginList, {}),
                                /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(___WEBPACK_IMPORTED_MODULE_4__.CurrentUser, {})
                            ]
                        })
                    ]
                })
            }),
            /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(antd__WEBPACK_IMPORTED_MODULE_2__.Layout, {
                children: [
                    params.name && /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(antd__WEBPACK_IMPORTED_MODULE_2__.Layout.Sider, {
                        className: styles.sider,
                        theme: 'light',
                        ref: sideMenuRef
                    }),
                    /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(antd__WEBPACK_IMPORTED_MODULE_2__.Layout.Content, {
                        className: styles.main,
                        children: /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", {
                            className: "amplifier-block",
                            children: /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_AdminContent__WEBPACK_IMPORTED_MODULE_7__.AdminContent, {})
                        })
                    })
                ]
            })
        ]
    });
};
const AdminProvider = (props)=>/*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(___WEBPACK_IMPORTED_MODULE_4__.NoticeManagerProvider, {
        children: /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(___WEBPACK_IMPORTED_MODULE_4__.CurrentAppInfoProvider, {
            children: /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(___WEBPACK_IMPORTED_MODULE_4__.NavigateIfNotSignIn, {
                children: /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(___WEBPACK_IMPORTED_MODULE_4__.RemoteCollectionManagerProvider, {
                    children: /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_variables__WEBPACK_IMPORTED_MODULE_6__.VariablesProvider, {
                        children: /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(___WEBPACK_IMPORTED_MODULE_4__.ACLRolesCheckProvider, {
                            children: props.children
                        })
                    })
                })
            })
        })
    });
const AdminLayout = (props)=>/*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(AdminProvider, {
        children: [
            /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_NoticeArea__WEBPACK_IMPORTED_MODULE_9__.NoticeArea, {}),
            /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(InternalAdminLayout, {
                ...props
            })
        ]
    });
class AdminLayoutPlugin extends _application_Plugin__WEBPACK_IMPORTED_MODULE_5__.Plugin {
    async afterAdd() {
        await this.app.pm.add(___WEBPACK_IMPORTED_MODULE_4__.RemoteSchemaTemplateManagerPlugin);
    }
    async load() {
        this.app.addComponents({
            AdminLayout
        });
    }
}
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
