import type { ActingAsScope } from "../services/AuthService"; import { adolescentGateReason, type AdolescentGateReason } from "./adolescentFeatureGate"; /** * A scoped switch-in shows one part of the subject's record and the way out, nothing else: billing their * invoices, messaging their Messages (an assist-only helper the patient let message for them). */ export const SCOPED_SWITCH_IN: Record; path: string }> = { billing: { navIds: new Set(["invoices", "logout"]), path: "/dashboard/my-invoices" }, messaging: { navIds: new Set(["messages", "logout"]), path: "/dashboard/messages" }, }; type SelfIdentity = Parameters[0]; export type ScopedSwitchInStep = | { kind: "stay" } | { kind: "go"; path: string } | { kind: "held"; reason: Exclude }; // Holds when Messages is 18+-closed to the signed-in helper; redirecting there would bounce home forever. export function scopedSwitchInStep(scope: ActingAsScope, pathname: string, self: SelfIdentity): ScopedSwitchInStep { if (scope === "messaging") { const reason = adolescentGateReason(self); if (reason !== "not-applicable") return { kind: "held", reason }; } const { path } = SCOPED_SWITCH_IN[scope]; return pathname === path ? { kind: "stay" } : { kind: "go", path }; }