export type HeaderMode = "public" | "app" | "module";
export type HeaderModeRequest = HeaderMode | "auto";

export function resolveHeaderMode(hasUser: boolean, requestedMode: HeaderModeRequest = "auto"): HeaderMode {
  if (requestedMode === "public") {
    return "public";
  }

  if (requestedMode === "app") {
    return hasUser ? "app" : "public";
  }

  if (requestedMode === "module") {
    return hasUser ? "module" : "public";
  }

  return hasUser ? "app" : "public";
}

export type HeaderVisibility = {
  mode: HeaderMode;
  showMarketingNav: boolean;
  showAuthButtons: boolean;
  showUserControls: boolean;
  showBackLink: boolean;
};

export function getHeaderVisibility(hasUser: boolean, requestedMode: HeaderModeRequest = "auto"): HeaderVisibility {
  const mode = resolveHeaderMode(hasUser, requestedMode);

  return {
    mode,
    showMarketingNav: mode === "public",
    showAuthButtons: mode === "public",
    showUserControls: mode !== "public" && hasUser,
    showBackLink: mode === "module" && hasUser,
  };
}
