export type WidgetSection = "status" | "appearance" | "tools";

export const WIDGET_SECTIONS: readonly WidgetSection[] = [
  "status",
  "appearance",
  "tools",
];

/**
 * The address of each tab, after the widget page's own. The dashboard's
 * `/widget` itself only redirects: to Aspetto once the widget is installed
 * (ACC-586, Widget_1), to the status before.
 */
export const WIDGET_SECTION_PATH: Record<WidgetSection, string> = {
  status: "/status",
  appearance: "/appearance",
  tools: "/tools",
};

/**
 * The tab an address shows, among the ones the host offers: the first of
 * them when the address names none.
 */
export function widgetSectionOf(
  pathname: string | null | undefined,
  sections: readonly WidgetSection[] = WIDGET_SECTIONS,
): WidgetSection {
  const named = sections.find((section) =>
    pathname?.endsWith(WIDGET_SECTION_PATH[section]),
  );
  return named ?? sections[0] ?? "status";
}
