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_lodash__ from "lodash";
import * as __WEBPACK_EXTERNAL_MODULE_react_router_dom__ from "react-router-dom";
const NavigateNoUpdateContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext(null);
NavigateNoUpdateContext.displayName = 'NavigateNoUpdateContext';
const LocationNoUpdateContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext(null);
LocationNoUpdateContext.displayName = 'LocationNoUpdateContext';
const LocationSearchContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext('');
LocationSearchContext.displayName = 'LocationSearchContext';
const IsAdminPageContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext(false);
IsAdminPageContext.displayName = 'IsAdminPageContext';
const CurrentPageUidContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext('');
CurrentPageUidContext.displayName = 'CurrentPageUidContext';
const MatchAdminContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext(false);
MatchAdminContext.displayName = 'MatchAdminContext';
const MatchAdminNameContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext(false);
MatchAdminNameContext.displayName = 'MatchAdminNameContext';
const IsInSettingsPageContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext(false);
IsInSettingsPageContext.displayName = 'IsInSettingsPageContext';
const CurrentTabUidContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext('');
CurrentTabUidContext.displayName = 'CurrentTabUidContext';
const SearchParamsContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext(new URLSearchParams());
SearchParamsContext.displayName = 'SearchParamsContext';
const RouterBasenameContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext('');
RouterBasenameContext.displayName = 'RouterBasenameContext';
const IsSubPageClosedByPageMenuContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext({
    isSubPageClosedByPageMenu: ()=>false,
    setFieldSchema: ()=>{},
    reset: ()=>{}
});
IsSubPageClosedByPageMenuContext.displayName = 'IsSubPageClosedByPageMenuContext';
const IsSubPageClosedByPageMenuProvider = (param)=>{
    let { children } = param;
    const params = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useParams)();
    const prevParamsRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)({});
    const [fieldSchema, setFieldSchema] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(null);
    const isSubPageClosedByPageMenu = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
        var _fieldSchema_xcomponentprops, _prevParamsRef_current_;
        const result = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].isEmpty(params['*']) && (null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.openMode) === 'page' && !!(null === (_prevParamsRef_current_ = prevParamsRef.current['*']) || void 0 === _prevParamsRef_current_ ? void 0 : _prevParamsRef_current_.includes(fieldSchema['x-uid']));
        prevParamsRef.current = params;
        return result;
    }, [
        fieldSchema,
        params
    ]);
    const reset = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
        prevParamsRef.current = {};
    }, []);
    const value = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            isSubPageClosedByPageMenu,
            setFieldSchema,
            reset
        }), [
        isSubPageClosedByPageMenu,
        reset
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(IsSubPageClosedByPageMenuContext.Provider, {
        value: value,
        children: children
    });
};
const RouterBasenameProvider = (param)=>{
    let { children } = param;
    const basenameOfCurrentRouter = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useHref)('/');
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(RouterBasenameContext.Provider, {
        value: basenameOfCurrentRouter,
        children: children
    });
};
const SearchParamsProvider = (param)=>{
    let { children } = param;
    const [searchParams] = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useSearchParams)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(SearchParamsContext.Provider, {
        value: searchParams,
        children: children
    });
};
const IsInSettingsPageProvider = (param)=>{
    let { children } = param;
    const isInSettingsPage = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useLocation)().pathname.includes('/settings');
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(IsInSettingsPageContext.Provider, {
        value: isInSettingsPage,
        children: children
    });
};
const MatchAdminProvider = (param)=>{
    let { children } = param;
    const isMatchAdmin = !!(0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useMatch)('/admin');
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(MatchAdminContext.Provider, {
        value: isMatchAdmin,
        children: children
    });
};
const MatchAdminNameProvider = (param)=>{
    let { children } = param;
    const isMatchAdminName = !!(0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useMatch)('/admin/:name');
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(MatchAdminNameContext.Provider, {
        value: isMatchAdminName,
        children: children
    });
};
const IsAdminPageProvider = (param)=>{
    let { children } = param;
    const location = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useLocation)();
    const isAdminPage = location.pathname.startsWith('/admin');
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(IsAdminPageContext.Provider, {
        value: isAdminPage,
        children: children
    });
};
const CurrentPageUidProvider = (param)=>{
    let { children } = param;
    const params = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useParams)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(CurrentPageUidContext.Provider, {
        value: params.name,
        children: children
    });
};
const CurrentTabUidProvider = (param)=>{
    let { children } = param;
    const params = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useParams)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(CurrentTabUidContext.Provider, {
        value: params.tabUid,
        children: children
    });
};
const NavigateNoUpdateProvider = (param)=>{
    let { children } = param;
    const navigate = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useNavigate)();
    const navigateRef = __WEBPACK_EXTERNAL_MODULE_react__["default"].useRef(navigate);
    navigateRef.current = navigate;
    const navigateNoUpdate = __WEBPACK_EXTERNAL_MODULE_react__["default"].useCallback((to, options)=>{
        navigateRef.current(to, options);
    }, []);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(NavigateNoUpdateContext.Provider, {
        value: navigateNoUpdate,
        children: children
    });
};
const LocationNoUpdateProvider = (param)=>{
    let { children } = param;
    const location = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useLocation)();
    const locationRef = __WEBPACK_EXTERNAL_MODULE_react__["default"].useRef({});
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        Object.assign(locationRef.current, location);
    }, [
        location
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(LocationNoUpdateContext.Provider, {
        value: locationRef.current,
        children: children
    });
};
const LocationSearchProvider = (param)=>{
    let { children } = param;
    const location = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useLocation)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(LocationSearchContext.Provider, {
        value: location.search,
        children: children
    });
};
const useNavigateNoUpdate = ()=>__WEBPACK_EXTERNAL_MODULE_react__["default"].useContext(NavigateNoUpdateContext);
const useLocationNoUpdate = ()=>__WEBPACK_EXTERNAL_MODULE_react__["default"].useContext(LocationNoUpdateContext);
const useLocationSearch = ()=>__WEBPACK_EXTERNAL_MODULE_react__["default"].useContext(LocationSearchContext);
const useIsAdminPage = ()=>__WEBPACK_EXTERNAL_MODULE_react__["default"].useContext(IsAdminPageContext);
const useCurrentPageUid = ()=>__WEBPACK_EXTERNAL_MODULE_react__["default"].useContext(CurrentPageUidContext);
const useMatchAdmin = ()=>__WEBPACK_EXTERNAL_MODULE_react__["default"].useContext(MatchAdminContext);
const useMatchAdminName = ()=>__WEBPACK_EXTERNAL_MODULE_react__["default"].useContext(MatchAdminNameContext);
const useIsInSettingsPage = ()=>__WEBPACK_EXTERNAL_MODULE_react__["default"].useContext(IsInSettingsPageContext);
const useCurrentTabUid = ()=>__WEBPACK_EXTERNAL_MODULE_react__["default"].useContext(CurrentTabUidContext);
const useCurrentSearchParams = ()=>__WEBPACK_EXTERNAL_MODULE_react__["default"].useContext(SearchParamsContext);
const useRouterBasename = ()=>__WEBPACK_EXTERNAL_MODULE_react__["default"].useContext(RouterBasenameContext);
const useIsSubPageClosedByPageMenu = (fieldSchema)=>{
    const { isSubPageClosedByPageMenu, setFieldSchema, reset } = __WEBPACK_EXTERNAL_MODULE_react__["default"].useContext(IsSubPageClosedByPageMenuContext);
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        setFieldSchema(fieldSchema);
    }, [
        fieldSchema,
        setFieldSchema
    ]);
    return {
        isSubPageClosedByPageMenu,
        reset
    };
};
const CustomRouterContextProvider = (param)=>{
    let { children } = param;
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(NavigateNoUpdateProvider, {
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(LocationNoUpdateProvider, {
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(IsAdminPageProvider, {
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(LocationSearchProvider, {
                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(MatchAdminProvider, {
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(MatchAdminNameProvider, {
                            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(SearchParamsProvider, {
                                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(RouterBasenameProvider, {
                                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(IsInSettingsPageProvider, {
                                        children: children
                                    })
                                })
                            })
                        })
                    })
                })
            })
        })
    });
};
export { CurrentPageUidContext, CurrentPageUidProvider, CurrentTabUidContext, CurrentTabUidProvider, CustomRouterContextProvider, IsSubPageClosedByPageMenuProvider, LocationSearchContext, useCurrentPageUid, useCurrentSearchParams, useCurrentTabUid, useIsAdminPage, useIsInSettingsPage, useIsSubPageClosedByPageMenu, useLocationNoUpdate, useLocationSearch, useMatchAdmin, useMatchAdminName, useNavigateNoUpdate, useRouterBasename };
