Spaces:
Sleeping
Sleeping
| 'use client'; | |
| import { demoAgencies, type DemoAgency } from '@/lib/mock-data'; | |
| export const ACENTE_SESSION_KEY = 'ajet360.acente.session.v1'; | |
| export const ACENTE_SESSION_EVENT = 'ajet360:acente-session'; | |
| export const DEFAULT_AGENCY_CODE = 'AJ-IST-001'; | |
| function canUseStorage() { | |
| return typeof window !== 'undefined' && Boolean(window.localStorage); | |
| } | |
| export function getCurrentAgencyCode(): string { | |
| if (!canUseStorage()) return DEFAULT_AGENCY_CODE; | |
| const code = window.localStorage.getItem(ACENTE_SESSION_KEY); | |
| if (!code) return DEFAULT_AGENCY_CODE; | |
| if (!demoAgencies.some((a) => a.code === code)) return DEFAULT_AGENCY_CODE; | |
| return code; | |
| } | |
| export function setCurrentAgencyCode(code: string): void { | |
| if (!canUseStorage()) return; | |
| if (!demoAgencies.some((a) => a.code === code)) return; | |
| window.localStorage.setItem(ACENTE_SESSION_KEY, code); | |
| window.dispatchEvent(new Event(ACENTE_SESSION_EVENT)); | |
| } | |
| export function getCurrentAgency(): DemoAgency { | |
| const code = getCurrentAgencyCode(); | |
| return demoAgencies.find((a) => a.code === code) ?? demoAgencies[0]!; | |
| } | |
| export function listAvailableAgencies(): DemoAgency[] { | |
| // Limit to 5 Turkish agencies for demo readability | |
| return demoAgencies.filter((a) => a.code.match(/^AJ-(IST|ANT|ANK|IZM|TRB)-/)); | |
| } | |