import { LOCAL_STORAGE_KEYS } from 'common/constants/local-storage' // PostHog multivariate flag for the new docs information architecture. export const IA_NAV_FLAG = 'docs-ia-mvp-v1' export type IaNavVariant = 'control' | 'option-1' const VARIANTS: IaNavVariant[] = ['control', 'option-1'] export const isIaNavVariant = (value: unknown): value is IaNavVariant => VARIANTS.includes(value as IaNavVariant) // A forced variant is kept for the browser session, because links don't carry the query parameter. export const IA_NAV_OVERRIDE_KEY = 'docs-ia-mvp-v1-override' // a disabled flag leaves the posthog response, and this cached value marks it as off export const IA_NAV_FLAG_OFF = 'off' // runs before paint, so a visitor on option-1 never sees the control nav the server renders. // the url override wins over the session override, then the layout the user picked, then the value from the last visit // a flag that is off ignores the picked layout, so the flag stays the kill switch export const IA_NAV_CACHE_SCRIPT = `try{var V=${JSON.stringify(VARIANTS)};var o=new URLSearchParams(location.search).get('${IA_NAV_FLAG}');var s=V.indexOf(o)>-1?o:sessionStorage.getItem('${IA_NAV_OVERRIDE_KEY}');if(V.indexOf(s)<0&&localStorage.getItem('${LOCAL_STORAGE_KEYS.IA_NAV_FLAG}')!=='${IA_NAV_FLAG_OFF}')s=localStorage.getItem('${LOCAL_STORAGE_KEYS.DOCS_LAYOUT_CHOICE}');var v=V.indexOf(s)>-1?s:localStorage.getItem('${LOCAL_STORAGE_KEYS.IA_NAV_FLAG}');if(v==='option-1')document.documentElement.dataset.iaNav='option-1'}catch(e){}` export const IA_NAV_PENDING_CLASS = 'in-data-[ia-nav=option-1]:invisible' // Requests that force a variant are rewritten under this segment so the server HTML has its nav. export const IA_NAV_ROUTE_SEGMENT = 'ia' export const iaNavRoutePrefix = (variant: IaNavVariant) => `/${IA_NAV_ROUTE_SEGMENT}/${variant}`