"use client"; import { DEMO_SESSION_KEY, type DemoSession, } from "@/lib/auth-config"; export function readDemoSession(): DemoSession | null { if (typeof window === "undefined") return null; try { const raw = window.localStorage.getItem(DEMO_SESSION_KEY); if (!raw) return null; return JSON.parse(raw) as DemoSession; } catch { return null; } } export function writeDemoSession(session: DemoSession): void { window.localStorage.setItem(DEMO_SESSION_KEY, JSON.stringify(session)); window.dispatchEvent(new Event("krypco-auth-change")); } export function clearDemoSession(): void { window.localStorage.removeItem(DEMO_SESSION_KEY); window.dispatchEvent(new Event("krypco-auth-change")); } export function createDemoEmailSession(email: string): DemoSession { return { kind: "demo", userId: `demo_${email.toLowerCase().replace(/[^a-z0-9]/g, "_")}`, label: email, createdAt: new Date().toISOString(), }; } export function createDemoWalletSession(address: string): DemoSession { const short = `${address.slice(0, 6)}…${address.slice(-4)}`; return { kind: "wallet", userId: `wallet_${address.toLowerCase()}`, label: short, walletAddress: address, createdAt: new Date().toISOString(), }; }