import { jsx } from "react/jsx-runtime";
import { useContext, useEffect } from "react";
import { css } from "@emotion/css";
import { Outlet, useLocation, useOutlet, useParams } from "react-router-dom";
import { useDocumentTitle } from "../document-title/index.mjs";
import { PageStyleContext } from "./PageStyle.provider.mjs";
import { usePageStyle } from "./usePageStyle.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: none;\n            "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const TabContentInternal = (param)=>{
    let { items, activeKey } = param;
    return items.map((item)=>/*#__PURE__*/ jsx("div", {
            className: activeKey !== item.key ? css(_templateObject()) : '',
            children: item.children
        }, item.key));
};
const TabContent = ()=>{
    const { title, setTitle } = useDocumentTitle();
    const location = useLocation();
    const { items, setItems } = useContext(PageStyleContext);
    const targetKey = location.pathname;
    const outlet = useOutlet();
    useEffect(()=>{
        if (targetKey && title) {
            const targetItem = items.find((value)=>value.key === targetKey);
            if (targetItem) setTitle(targetItem.label);
            else setItems([
                ...items,
                {
                    key: targetKey,
                    label: title,
                    children: outlet
                }
            ]);
        }
    }, [
        targetKey,
        title
    ]);
    return /*#__PURE__*/ jsx(TabContentInternal, {
        items: items,
        activeKey: targetKey
    });
};
const CustomAdminContent = ()=>{
    const params = useParams();
    const pageStyle = usePageStyle();
    return params.name && 'tab' === pageStyle ? /*#__PURE__*/ jsx(TabContent, {}) : /*#__PURE__*/ jsx(Outlet, {});
};
export { CustomAdminContent, TabContent, TabContentInternal };
