"use strict";var __rest=this&&this.__rest||function(e,t){var o={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(r=Object.getOwnPropertySymbols(e);s<r.length;s++)t.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(e,r[s])&&(o[r[s]]=e[r[s]])}return o};Object.defineProperty(exports,"__esModule",{value:!0}),exports.unsupportedFeatureScreenAtom=exports.languageAtom=exports.getLangKey=exports.collapsedSidebarAtom=exports.appSessionStore=exports.layoutAtom=exports.activeMimeNameAtom=exports.isSidebarOpenedAtom=exports.environmentAtom=exports.environmentsAtom=exports.appStoreOverrideAtom=exports.appStore=void 0;const jotai_1=require("jotai"),utils_1=require("jotai/utils"),theme_1=require("@redocly/theme"),cookies_1=require("../utils/cookies"),store_1=require("./store"),environments_1=require("../utils/environments"),utils_2=require("../utils"),defaultAppStoreValue={isSidebarOpened:!0,activeMimeName:"",layout:theme_1.LayoutVariant.THREE_PANEL,language:"",environment:"",environments:{}},customStorage={getItem:e=>{var t,o;const r=(0,utils_2.safeJsonParse)((0,cookies_1.getCookie)(e,null===(o=null===(t=globalThis.redoclyCookieStorage)||void 0===t?void 0:t.getStore)||void 0===o?void 0:o.call(t))),s=(0,utils_2.safeJsonParse)((0,utils_2.fromSessionStorage)(e));return Object.assign(Object.assign(Object.assign({},defaultAppStoreValue),s),r)},setItem:(e,t)=>{const{environments:o,layout:r}=t,s=__rest(t,["environments","layout"]),n={environments:o};(0,cookies_1.setCookie)(e,JSON.stringify(s)),(0,utils_2.toSessionStorage)(e,JSON.stringify(n))},removeItem:e=>{(0,cookies_1.removeCookie)(e),sessionStorage.removeItem(e)}};function getLangKey({lang:e,label:t}){return(t||e).toLowerCase()}exports.appStore=(0,utils_1.atomWithStorage)("redoc.appStore",defaultAppStoreValue,customStorage),exports.appStoreOverrideAtom=(0,jotai_1.atom)({}),exports.environmentsAtom=(0,jotai_1.atom)((e=>{const t=e(exports.appStore),o=e(exports.appStoreOverrideAtom);return(0,environments_1.mergeEnvData)(t.environments,(null==o?void 0:o.environments)||{})})),exports.environmentAtom=(0,jotai_1.atom)((e=>{const t=e(exports.appStore),o=e(exports.appStoreOverrideAtom),r=(0,environments_1.mergeEnvData)(t.environments,(null==o?void 0:o.environments)||{}),s=(null==o?void 0:o.environment)||t.environment,n=r[s]?s:Object.keys(r)[0];return[r[n]||{},n||""]}),((e,t,{environment:o,environments:r})=>{const s=e(exports.appStore);t(exports.appStore,Object.assign(Object.assign({},s),{environment:o||s.environment,environments:(0,environments_1.mergeEnvData)(s.environments||{},r)}))})),exports.isSidebarOpenedAtom=(0,jotai_1.atom)((e=>e(exports.appStore).isSidebarOpened),((e,t,o)=>{const r=e(exports.appStore);t(exports.appStore,Object.assign(Object.assign({},r),{isSidebarOpened:o}))})),exports.activeMimeNameAtom=(0,jotai_1.atom)((e=>e(exports.appStore).activeMimeName),((e,t,o)=>{const r=e(exports.appStore);t(exports.appStore,Object.assign(Object.assign({},r),{activeMimeName:o}))})),exports.layoutAtom=(0,jotai_1.atom)((e=>e(exports.appStore).layout),((e,t,o=theme_1.LayoutVariant.STACKED)=>{const r=e(exports.appStore);t(exports.appStore,Object.assign(Object.assign({},r),{layout:o}))})),exports.appSessionStore=(0,utils_1.atomWithStorage)("redoc.appSessionStore",{collapsedSidebar:!1,unsupportedFeatureScreen:!1},theme_1.IS_BROWSER?(0,utils_1.createJSONStorage)((()=>sessionStorage)):void 0),exports.collapsedSidebarAtom=(0,jotai_1.atom)((e=>e(exports.appSessionStore).collapsedSidebar),((e,t,o)=>{const r=e(exports.appSessionStore);t(exports.appSessionStore,Object.assign(Object.assign({},r),{collapsedSidebar:o}))})),exports.getLangKey=getLangKey,exports.languageAtom=(0,jotai_1.atom)((e=>{var t;const{codeSamples:o}=e(store_1.globalOptionsAtom),r=o.languages.map((({lang:e,label:t},o)=>({key:getLangKey({lang:e,label:t}),lang:e,title:t||e,order:o}))),s=e(exports.appStore).language||r[0].key;return{languages:r,activeLanguage:(null===(t=r.find((({key:e})=>e===s)))||void 0===t?void 0:t.key)||r[0].key}}),((e,t,o)=>{const r=e(exports.appStore);t(exports.appStore,Object.assign(Object.assign({},r),{language:o}))})),exports.unsupportedFeatureScreenAtom=(0,jotai_1.atom)((e=>e(exports.appSessionStore).unsupportedFeatureScreen),((e,t,o)=>{const r=e(exports.appSessionStore);t(exports.appSessionStore,Object.assign(Object.assign({},r),{unsupportedFeatureScreen:o}))}));
//# sourceMappingURL=app.js.map