"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.languageAtom=exports.collapsedSidebarAtom=exports.appSessionStore=exports.userClaimsAtom=exports.layoutAtom=exports.activeMimeNameAtom=exports.isSidebarOpenedAtom=exports.environmentAtom=exports.environmentsAtom=exports.appStoreOverrideAtom=exports.appStore=void 0,exports.getLangKey=getLangKey;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:{},userClaims:{}},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}=t,r=__rest(t,["environments"]),s={environments:o};(0,cookies_1.setCookie)(e,JSON.stringify(r)),(0,utils_2.toSessionStorage)(e,JSON.stringify(s))},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,a=r[s]?s:Object.keys(r)[0];return[r[a]||{},a||""]}),((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.userClaimsAtom=(0,jotai_1.atom)((e=>e(exports.appStore).userClaims),((e,t,o)=>{const r=e(exports.appStore);t(exports.appStore,Object.assign(Object.assign({},r),{userClaims: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.languageAtom=(0,jotai_1.atom)((e=>{var t,o,r;const{codeSamples:s}=e(store_1.globalOptionsAtom),a=s.languages.map((({lang:e,label:t},o)=>({key:getLangKey({lang:e,label:t}),lang:e,title:t||e,order:o}))),n=e(exports.appStore).language||(null===(t=a[0])||void 0===t?void 0:t.key);return{languages:a,activeLanguage:(null===(o=a.find((({key:e})=>e===n)))||void 0===o?void 0:o.key)||(null===(r=a[0])||void 0===r?void 0:r.key)}}),((e,t,o)=>{const r=e(exports.appStore);t(exports.appStore,Object.assign(Object.assign({},r),{language:o}))}));
//# sourceMappingURL=app.js.map