import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE_react_helmet__ from "react-helmet";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__application_Plugin_mjs__ from "../../application/Plugin.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../schema-component/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__system_settings_index_mjs__ from "../system-settings/index.mjs";
const DocumentTitleContext = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)({
    title: null,
    setTitle () {}
});
DocumentTitleContext.displayName = 'DocumentTitleContext';
const DocumentTitleProvider = (props)=>{
    const compile = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useCompile)();
    const { addonBefore, addonAfter } = props;
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const [title, setTitle] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)('');
    const documentTitle = "".concat(addonBefore ? " - ".concat(t(addonBefore)) : '').concat(t(compile(title) || '')).concat(addonAfter ? " - ".concat(t(addonAfter)) : '');
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(DocumentTitleContext.Provider, {
        value: {
            title,
            setTitle
        },
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_helmet__.Helmet, {
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("title", {
                    children: documentTitle
                })
            }),
            props.children
        ]
    });
};
const RemoteDocumentTitleProvider = (props)=>{
    var _ctx_data_data, _ctx_data;
    const ctx = (0, __WEBPACK_EXTERNAL_MODULE__system_settings_index_mjs__.useSystemSettings)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(DocumentTitleProvider, {
        addonAfter: null == ctx ? void 0 : null === (_ctx_data = ctx.data) || void 0 === _ctx_data ? void 0 : null === (_ctx_data_data = _ctx_data.data) || void 0 === _ctx_data_data ? void 0 : _ctx_data_data.title,
        children: props.children
    });
};
const useDocumentTitle = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(DocumentTitleContext);
const useCurrentDocumentTitle = (title)=>{
    const { setTitle } = useDocumentTitle();
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        setTitle(title);
    }, []);
};
class RemoteDocumentTitlePlugin extends __WEBPACK_EXTERNAL_MODULE__application_Plugin_mjs__.Plugin {
    async load() {
        this.app.use(RemoteDocumentTitleProvider, this.options);
    }
}
export { DocumentTitleContext, DocumentTitleProvider, RemoteDocumentTitlePlugin, RemoteDocumentTitleProvider, useCurrentDocumentTitle, useDocumentTitle };
