// Opportunities — customer-facing intelligence surface (Phase B Stage 3).
// Route: /{slug}/opportunities.
//
// Renders the prioritized opportunities the cfo-synthesis service returns for
// this tenant (surface_type="opportunities"). The page is a thin shell: it owns
// only the header and hands the fetch/loading/empty/footer + card rendering to
// the shared <SynthesizedSurface>. It reads ONLY the synthesis service output —
// no engine logic, no catalog reads, no signal-set parsing here. The structure
// is universal across archetypes; only the synthesized content varies.

(function () {
  const R = window.React;
  if (!R) return;

  function OpportunitiesPage({ scopedCompanyId, companyProfile, setPage, setDrillKey }) {
    const tenantId = scopedCompanyId || (companyProfile && companyProfile.id) || null;

    return R.createElement("div", { className: "pc-page", "data-page": "opportunities" },
      window.PageExplainer
        ? R.createElement(window.PageExplainer, {
          id: "opportunities",
          title: "Opportunities",
          body: R.createElement(R.Fragment, null,
            "Money or operating leverage you can capture right now, ranked by dollar impact. ",
            "Each opportunity is computed from your live general ledger and explained by Perdura's ",
            "CFO intelligence — every figure traces to a real signal in your data. ",
            "We only surface what the numbers support; if there's nothing material, we say so."),
        })
        : R.createElement("h1", { style: { fontSize: 22, fontWeight: 800, marginBottom: 4 } }, "Opportunities"),

      tenantId
        ? R.createElement(window.SynthesizedSurface || "div", {
          tenantId,
          surfaceType: "opportunities",
          max: 6,
          loadingLabel: "Scanning your financials for opportunities…",
          emptyTitle: "No opportunities to surface right now",
          emptyDetail: "We reviewed your receivables, spend, and margins and found nothing this period that rises to a concrete, dollar-quantified opportunity. We'll surface items here as soon as your data shows recoverable value.",
          setPage,
          setDrillKey,
        })
        : R.createElement(window.IntelEmptyState || "div", {
          title: "Connect your data to see opportunities",
          detail: "Once your general ledger is connected, Perdura will surface dollar-quantified opportunities here.",
        })
    );
  }

  window.OpportunitiesPage = OpportunitiesPage;
})();
