/* Claims Desk — the route table.
   Deliberately NOT routes: the ⌘K palette, the notifications *panel* (the panel
   is a state of the bar; /notifications behind it is the destination), the row
   menus, the confirm dialogs, the record-response and record-recovery dialogs,
   the queue's tabs and text filter. They are states of a screen, not
   destinations — a breadcrumb that wants one of them is a bug in the screen.

   Five top-level destinations, so this product still runs the TOP-NAV shell.
   The claim's own three views (assessment, evidence, decision) and the four
   settings views are registered routes reached by tabs inside their own
   surface, never a second row of navigation. */

const CLAIMS_NAV = [
  { path: "/", label: "Work queue", badge: "claimsDecidable" },
  { path: "/signoff", label: "Sign-off", badge: "signoffWaiting" },
  { path: "/payments", label: "Payments", badge: "settlementsToSchedule" },
  { path: "/responses", label: "Responses", badge: "offersDisputed" },
  { path: "/recovery", label: "Recovery", badge: "recoveriesToFile" },

  /* Registered, not in the nav. */
  { path: "/claims/new", label: "New claim", parent: "/", offSidebar: true, group: "Create" },
  { path: "/claims/:id", label: "Claim", parent: "/", offSidebar: true },
  { path: "/claims/:id/evidence", label: "Evidence", parent: "/claims/:id", offSidebar: true },
  { path: "/claims/:id/decision", label: "Decision", parent: "/claims/:id", offSidebar: true },
  { path: "/recovery/new", label: "New recovery", parent: "/recovery", offSidebar: true, group: "Create" },
  { path: "/recovery/:id", label: "Recovery file", parent: "/recovery", offSidebar: true },
  /* A claimant is reached from any of its claims and from the palette, never
     from one destination, so it hangs under no parent and its breadcrumb is
     its own name. */
  { path: "/claimants/:id", label: "Claimant", parent: "/", offSidebar: true },
  { path: "/notifications", label: "Notifications", offSidebar: true },
  /* Settings: /settings IS the profile view, so the area has no empty namespace
     parent and no route resolving to a redirect. The other three hang off it
     and are reached by the tab strip. */
  { path: "/settings", label: "Settings", offSidebar: true },
  { path: "/settings/authority", label: "Authority", parent: "/settings", offSidebar: true },
  { path: "/settings/alerts", label: "Alerts", parent: "/settings", offSidebar: true },
  { path: "/settings/desk", label: "Desk", parent: "/settings", offSidebar: true },

  /* Auth namespace — excluded from the shell nav; no product chrome. */
  { path: "/signin", label: "Sign in", offSidebar: true },
  { path: "/signout", label: "Sign out", offSidebar: true },
];

const CLAIMS_ROUTES = indexRoutes(CLAIMS_NAV);

/* Projections the shell renders — derived by filtering the tree, never retyped. */
const CLAIMS_DESTINATIONS = CLAIMS_NAV.filter((r) => !r.offSidebar);

const CLAIMS_ACCOUNT_MENU = [
  CLAIMS_ROUTES["/settings"],
  CLAIMS_ROUTES["/signout"],
];

/* The claim's own views, in tab order. Registered routes, filtered from the
   tree — the tab strip never carries a label the route table does not have. */
const CLAIM_VIEWS = [
  { value: "assessment", route: CLAIMS_ROUTES["/claims/:id"], label: "Assessment" },
  { value: "evidence", route: CLAIMS_ROUTES["/claims/:id/evidence"], label: "Evidence" },
  { value: "decision", route: CLAIMS_ROUTES["/claims/:id/decision"], label: "Decision" },
];

/* The settings views, same device. The first tab's route is /settings itself,
   whose table label is the area's name rather than the view's. */
const SETTINGS_VIEWS = [
  { value: "profile", route: CLAIMS_ROUTES["/settings"], label: "Profile" },
  { value: "authority", route: CLAIMS_ROUTES["/settings/authority"], label: "Authority" },
  { value: "alerts", route: CLAIMS_ROUTES["/settings/alerts"], label: "Alerts" },
  { value: "desk", route: CLAIMS_ROUTES["/settings/desk"], label: "Desk" },
];

/* Paths that render without product chrome (AGENTS §7.1). */
const CLAIMS_AUTH_PATHS = ["/signin", "/signout"];

/* The preview menu's page list — this table read whole and grouped, never
   retyped, with the parameterised routes resolved against the fixture so the
   link lands on a real record rather than on ":id". A pattern with no fixture
   example is left out rather than offered as a link resolving nowhere. */
const CLAIMS_PAGES = (data) => {
  const claim = data.claims[0], recovery = data.recoveries[0];
  const claimant = claim ? (data.claimants || []).find((p) => p.name === claim.customer) : null;
  return templatePages(CLAIMS_NAV, CLAIMS_AUTH_PATHS, {
    "/claims/:id": claim ? "/claims/" + claim.id : null,
    "/claims/:id/evidence": claim ? "/claims/" + claim.id + "/evidence" : null,
    "/claims/:id/decision": claim ? "/claims/" + claim.id + "/decision" : null,
    "/recovery/:id": recovery ? "/recovery/" + recovery.id : null,
    "/claimants/:id": claimant ? "/claimants/" + claimant.id : null,
  });
};

Object.assign(window, { CLAIMS_AUTH_PATHS, CLAIMS_NAV, CLAIMS_ROUTES, CLAIMS_DESTINATIONS, CLAIMS_ACCOUNT_MENU, CLAIM_VIEWS, SETTINGS_VIEWS, CLAIMS_PAGES });
