import { jsx, jsxs } from "react/jsx-runtime";
import { useRef } from "react";
import { css } from "@emotion/css";
import { Layout } from "antd";
import { Navigate, useLocation } from "react-router";
import { Outlet } from "react-router-dom";
import { useAPIClient } from "../../api-client/index.mjs";
import { AdminProvider, AdminTabs, MenuEditor, useStyles } from "../../built-in/admin-layout/index.mjs";
import { PinnedPluginList } from "../../built-in/pinned-list/index.mjs";
import { useSystemSettings } from "../../built-in/system-settings/index.mjs";
import { CurrentUser } from "../../user/index.mjs";
import { useApp } from "../hooks/index.mjs";
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n          display: flex;\n          flex-direction: column;\n          position: relative;\n          overflow-y: auto;\n          > div {\n            position: relative;\n          }\n          .ant-layout-footer {\n            position: absolute;\n            bottom: 0;\n            text-align: center;\n            width: 100%;\n            z-index: 0;\n            padding: 0px 50px;\n          }\n        "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
function useShareToken() {
    const url = new URL(window.location.href);
    const api = useAPIClient();
    const token = url.searchParams.get('token');
    return token && api.auth.setToken(token), api.auth.getToken();
}
const ShareLayout = ()=>{
    var _result_data_data_logo, _result_data_data, _result_data, _result_data_data1, _result_data1;
    const { styles } = useStyles();
    const app = useApp();
    const result = useSystemSettings();
    const sideMenuRef = useRef();
    return /*#__PURE__*/ jsx(Layout, {
        style: {
            height: '100%'
        },
        children: /*#__PURE__*/ jsxs(Layout.Content, {
            className: css(_templateObject()),
            children: [
                /*#__PURE__*/ jsx(Layout.Header, {
                    className: styles.header,
                    children: /*#__PURE__*/ jsxs("div", {
                        className: styles.headerA,
                        children: [
                            /*#__PURE__*/ jsxs("div", {
                                className: styles.headerB,
                                children: [
                                    /*#__PURE__*/ jsxs("div", {
                                        className: styles.titleContainer,
                                        onClick: ()=>{
                                            location.href = app.adminUrl;
                                        },
                                        children: [
                                            /*#__PURE__*/ jsx("img", {
                                                className: styles.logo,
                                                src: null == result ? void 0 : null == (_result_data = result.data) ? void 0 : null == (_result_data_data = _result_data.data) ? void 0 : null == (_result_data_data_logo = _result_data_data.logo) ? void 0 : _result_data_data_logo.url
                                            }),
                                            /*#__PURE__*/ jsx("h1", {
                                                className: styles.title,
                                                children: null == result ? void 0 : null == (_result_data1 = result.data) ? void 0 : null == (_result_data_data1 = _result_data1.data) ? void 0 : _result_data_data1.title
                                            })
                                        ]
                                    }),
                                    /*#__PURE__*/ jsx(MenuEditor, {
                                        sideMenuRef: sideMenuRef
                                    }),
                                    /*#__PURE__*/ jsx("div", {
                                        className: styles.headerTabs,
                                        children: /*#__PURE__*/ jsx(AdminTabs, {})
                                    })
                                ]
                            }),
                            /*#__PURE__*/ jsxs("div", {
                                className: styles.right,
                                children: [
                                    /*#__PURE__*/ jsx(PinnedPluginList, {
                                        belongToFilter: "pinnedmenu"
                                    }),
                                    /*#__PURE__*/ jsx(CurrentUser, {})
                                ]
                            })
                        ]
                    })
                }),
                /*#__PURE__*/ jsx(Outlet, {})
            ]
        })
    });
};
const SharePage = ()=>{
    const shareToken = useShareToken();
    return shareToken ? /*#__PURE__*/ jsx(AdminProvider, {
        children: /*#__PURE__*/ jsx(ShareLayout, {})
    }) : /*#__PURE__*/ jsx(NotAuthorityResult, {});
};
function NotAuthorityResult() {
    const { pathname, search } = useLocation();
    const redirect = "?redirect=".concat(pathname).concat(search);
    return /*#__PURE__*/ jsx(Navigate, {
        replace: true,
        to: "/signin".concat(redirect)
    });
}
export { NotAuthorityResult, ShareLayout, SharePage, useShareToken };
