import { jsx } from "react/jsx-runtime";
import react from "react";
import { useLocalStorageState } from "ahooks";
import { useTranslation } from "react-i18next";
import { Plugin } from "../../application/Plugin.mjs";
import { DynamicPage } from "./DynamicPage.mjs";
class PluginDynamicPage extends Plugin {
    async beforeLoad() {
        this.app.use(PageModeProvider);
    }
    async load() {
        this.app.router.remove('app.page');
        this.app.router.add('app.page', {
            path: '/:entry/:name/*',
            Component: DynamicPage
        });
        this.app.usePageMode = usePageMode;
    }
    async afterLoad() {
        this.app.pluginContextMenu.add(pageMode.name, pageMode);
    }
}
const PageModeContext = /*#__PURE__*/ react.createContext({
    enable: false,
    setEnable: ()=>{}
});
const PageModeProvider = (param)=>{
    let { children } = param;
    const [enable, setEnable] = useLocalStorageState('tb-page-mode', {
        defaultValue: false
    });
    return /*#__PURE__*/ jsx(PageModeContext.Provider, {
        value: {
            enable,
            setEnable
        },
        children: children
    });
};
const usePageMode = ()=>react.useContext(PageModeContext);
const pageMode = {
    name: 'pageMode',
    useLoadMethod: ()=>{
        const { enable, setEnable } = usePageMode();
        const { t } = useTranslation();
        return {
            title: t('Page mode: {{enabled}}', {
                enabled: enable ? 'On' : 'Off'
            }),
            actionProps: {
                onClick: ()=>{
                    setEnable(!enable);
                }
            }
        };
    }
};
export { PageModeContext, PageModeProvider, PluginDynamicPage, usePageMode };
