import { Component } from '@angular/core'; const IONIC_SESSION_KEY = 'ionic-persist-config'; const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined'; const getStoredMode = (): string => { if (!isBrowser) return 'md'; // A ?ionic:mode= URL param wins over session, matching core's config merge // (configFromURL takes precedence over configFromSession). Read it first so // the label reflects what Ionic will actually render on URL-pinned pages. const urlMode = new URLSearchParams(window.location.search).get('ionic:mode'); if (urlMode === 'ios' || urlMode === 'md') return urlMode; try { const stored = sessionStorage.getItem(IONIC_SESSION_KEY); if (stored) { const config = JSON.parse(stored); if (config.mode) return config.mode; } } catch { // ignore } return document.documentElement.getAttribute('mode') || 'md'; }; const setStoredMode = (mode: string) => { try { const stored = sessionStorage.getItem(IONIC_SESSION_KEY); const config = stored ? JSON.parse(stored) : {}; config.mode = mode; sessionStorage.setItem(IONIC_SESSION_KEY, JSON.stringify(config)); } catch { // ignore } }; const isTestEnvironment = (): boolean => { // Hide during SSR (no DOM) and automated e2e runs. Most base Playwright specs // navigate without ionic:_testing=true, so navigator.webdriver (true under any // WebDriver/CDP-driven browser) is the primary guard that keeps this fixed, // high-z-index button from overlapping page UI during tests. The component is // intentionally visible in normal browsers, including Vercel previews, as a // reviewer convenience for flipping iOS/MD without editing the URL. if (!isBrowser) return true; const params = new URLSearchParams(window.location.search); return params.get('ionic:_testing') === 'true' || !!(window as any).Cypress || !!navigator.webdriver; }; @Component({ selector: 'app-mode-switcher', standalone: true, template: ` @if (!isTest) {