/**
 * SET 48 / 49 — pure main-area routing.
 *
 * Run-entry clicks must open the RUN view by id, never by record shape.
 * Admin / install panels are reachable only via their explicit doors.
 */

export type MainSurface = 'install' | 'admin' | 'run' | 'job' | 'empty';

export type SurfaceFlags = {
  installPanelOpen: boolean;
  adminOpen: boolean;
  t1Open: boolean;
  hasActiveJob: boolean;
};

/** Priority matches App.tsx main ternary: install → admin → run → job → empty. */
export function resolveMainSurface(f: SurfaceFlags): MainSurface {
  if (f.installPanelOpen) return 'install';
  if (f.adminOpen) return 'admin';
  if (f.t1Open) return 'run';
  if (f.hasActiveJob) return 'job';
  return 'empty';
}

/** SET 48 — after a Web-runs entry click: RUN view, always. */
export function flagsAfterRunEntryClick(): Pick<SurfaceFlags, 'installPanelOpen' | 'adminOpen' | 't1Open'> {
  return { installPanelOpen: false, adminOpen: false, t1Open: true };
}

/** Sidebar summary line → install panel only. */
export function flagsAfterInstallSummaryClick(): Pick<SurfaceFlags, 'installPanelOpen' | 'adminOpen' | 't1Open'> {
  return { installPanelOpen: true, adminOpen: false, t1Open: false };
}

/** Footer admin link → global AdminView only. */
export function flagsAfterAdminClick(): Pick<SurfaceFlags, 'installPanelOpen' | 'adminOpen' | 't1Open'> {
  return { installPanelOpen: false, adminOpen: true, t1Open: false };
}

/** Boot defaults — control panel (empty main), never admin/install/run. */
export function bootSurfaceFlags(): SurfaceFlags {
  return {
    installPanelOpen: false,
    adminOpen: false,
    t1Open: false,
    hasActiveJob: false,
  };
}
