/* eslint-disable */
const { useState, useMemo, useEffect } = React;

// ----- variations data -----

// ── DEVELOPER NOTE ─────────────────────────────────────────────────────────
// This is the pricing SECTION only — the site header and footer have been
// removed so this slots into another page.
//
// Before shipping, please:
//   • Cross-check every price, credit count, image/video count, and per-100
//     cost in this file (COMPARISON_ROWS, COMPETITORS) AND in pricing-data.jsx
//     (CREDIT_PACKS, MONTHLY_PLANS) against the live, approved pricing.
//   • Review the FAQ in pricing-data.jsx (FAQ_ITEMS). Replace any answers
//     that don't fit the final product, drop questions that don't apply,
//     and add any that customers actually ask. Treat it as a living list,
//     not a fixed set.
//   • Confirm the competitor table claims (COMPETITORS) are still accurate
//     and that "Authentic x AI Hybrid" / "Real/Edited and AI" copy reads
//     correctly for legal.
//
// Anything in this file is fair game to rename, restructure, or replace.
// ───────────────────────────────────────────────────────────────────────────

const COMPARISON_ROWS = [
  { label: "One-time credit pack price", section: true, values: ["", "", "", ""] },
  { label: "Pack price", values: ["$15", "$36", "$80", "$180"] },
  { label: "Credits", values: ["3,000", "8,000", "20,000", "50,000"] },
  { label: "Per-100-credit cost", values: ["$0.50", "$0.45", "$0.40", "$0.36"] },
  { label: "Expires", values: ["Never", "Never", "Never", "Never"] },

  { label: "Monthly plan equivalent", section: true, values: ["", "", "", ""] },
  { label: "Monthly price", values: ["$13/mo", "$30/mo", "$68/mo", "—"] },
  { label: "Credits / month", values: ["3,000", "8,000", "20,000", "—"] },
  { label: "Per-100-credit cost (monthly)", values: ["$0.43", "$0.38", "$0.34", "—"] },
  { label: "Cancel", values: ["Anytime", "Anytime", "Anytime", "—"] },

  { label: "Output (credit cost per generation)", section: true, values: ["", "", "", ""] },
  { label: "Image, 2K — 100 credits each", values: ["30", "80", "200", "500"] },
  { label: "Image, 4K — 200 credits each", values: ["15", "40", "100", "250"] },
  { label: "Chat refine — 75 credits each", values: ["40", "106", "266", "666"] },
  { label: "Video, 5s standard — 150 credits", values: ["20", "53", "133", "333"] },
  { label: "Video, 10s standard — 300 credits", values: ["10", "26", "66", "166"] },
  { label: "Video, 5s premium — 500 credits", values: ["6", "16", "40", "100"] },
  { label: "Video, 10s premium — 1,000 credits", values: ["3", "8", "20", "50"] },
];
COMPARISON_ROWS[0].cols = ["Creator", "Studio", "Scale", "Business"];

const TESTIMONIALS = [
  {
    quote: "We replaced a six-figure shoot budget with the Studio plan. Same hero shots, three days instead of three months.",
    name: "Maya Okafor",
    role: "Brand Director · Soma Bath Co.",
  },
  {
    quote: "The credit math is the cleanest part. I know exactly how many heroes a campaign costs before I open the brief.",
    name: "Daniel Reeve",
    role: "Founder · North Field Goods",
  },
  {
    quote: "Our seasonal drops used to need a stylist, a studio, and a week. Now they need an afternoon and a Scale plan.",
    name: "Ines Dahl",
    role: "Creative Lead · Mira Mira",
  },
];

const COMPETITORS = {
  cols: [
    { name: "Creative Studio", sub: "Studio plan, 2K hero" },
    { name: "Traditional shoot", sub: "Day rate, mid-tier" },
    { name: "Generic AI tool", sub: "Per-image, no library" },
    { name: "Stock + retouch", sub: "Licence + freelance" },
  ],
  rows: [
    { label: "Cost per hero image", values: ["$0.45", "$5000+", "$2 – $8", "$45 – $120"] },
    { label: "Lead time", values: ["~2 minutes", "2 – 6 weeks", "10 minutes", "Instant"] },
    { label: "Real product fidelity", values: ["Authentic x AI Hybrid", "Real shot", "Often warps", "Real/Edited and AI"] },
    { label: "Library scenes", values: ["10,000+", "N/A", "N/A", "Stock only"] },
    { label: "Iteration cost", values: ["$0.45 - 100 credits", "Reshoot", "Per-image again", "N/A"] },
    { label: "Commercial licence", values: ["Included", "Negotiated", "Varies", "Higher Priced"] },
  ],
};

// ----- main app -----

function PricingApp() {
  // Hardcoded settings — was a dev-only tweak panel during design handoff,
  // dropped for production. Defaults match what the page should always look like.
  const tweaks = {
    theme: "Cream",
    highlight: "Studio",
    showGenerations: false,
    showCompare: true,
    showCompetitors: true,
    showTestimonials: false,
    showBeforeAfter: true,
  };

  // Opens on monthly plans: they are the cheaper way in (Kate, 13 Oct 2026).
  const [mode, setMode] = useState("plans");
  const plans = mode === "packs" ? window.CREDIT_PACKS : window.MONTHLY_PLANS;

  // map highlight choice (by name) to id
  const highlightId = useMemo(() => {
    const match = plans.find((p) => p.name.toLowerCase() === tweaks.highlight.toLowerCase());
    return match ? match.id : plans.find((p) => p.featured)?.id;
  }, [tweaks.highlight, mode]);

  const [selectedId, setSelectedId] = useState(highlightId);
  const [expandedAll, setExpandedAll] = useState(false);

  useEffect(() => {
    setSelectedId(highlightId);
  }, [highlightId]);

  const selected = plans.find((p) => p.id === selectedId) || plans.find((p) => p.featured);

  // Theme switcher removed — the page now inherits the landing palette via
  // the CSS :root aliases declared in Pricing.html.

  // One column per plan so all cards sit on a single row on desktop (4 packs
  // or 3 monthly plans). Tablet/phone breakpoints override this via !important.
  const cardCols = `repeat(${plans.length}, minmax(0,1fr))`;

  return (
    <div data-screen-label="Pricing landing page">
      <div className="pp-top">
      <window.Hero />

      <window.ModeToggle mode={mode} onChange={setMode} />

      <section className="pp-cards-section" style={{ padding: "0 40px", maxWidth: 1640, margin: "0 auto" }}>
        <div
          className="pp-cards"
          style={{
            display: "grid",
            gridTemplateColumns: cardCols,
            gap: 16,
            alignItems: "stretch",
          }}
        >
          {plans.map((p) => (
            <PlainerCard
              key={p.id}
              plan={p}
              mode={mode}
              showGenerations={tweaks.showGenerations}
              selected={selectedId === p.id}
              onSelect={() => {
                setSelectedId(p.id);
                // Fire AddToCart for Meta when the user picks a specific tier.
                // Dedup so we never double-fire for the same tier in a session.
                // No-op until cookie consent is granted (see pixel.js).
                if (typeof window !== "undefined" && window.psPixel) {
                  const tier = String(p.id).replace(/-m$/, "");
                  const fired = window._psAddedToCart || (window._psAddedToCart = new Set());
                  if (!fired.has(tier)) {
                    const data = { content_ids: [tier], content_type: "product" };
                    if (p.price) { data.value = p.price; data.currency = "USD"; }
                    window.psPixel.track("AddToCart", data);
                    fired.add(tier);
                  }
                }
              }}
              expanded={expandedAll}
              onToggleExpand={() => setExpandedAll((v) => !v)}
            />
          ))}
        </div>

        <div
          style={{
            display: "flex",
            flexDirection: "column",
            alignItems: "center",
            gap: 14,
            marginTop: 56,
          }}
        >
          <window.CheckoutCTA selected={selected} mode={mode} />
          <div className="italic-serif" style={{ color: "var(--ink-mute)", fontSize: 14 }}>
            You picked <span style={{ fontStyle: "normal", fontWeight: 600, color: "var(--ink)" }}>{selected?.name}</span>
            {" · "}${selected?.price}{mode === "plans" ? "/mo" : ""} · {selected?.credits.toLocaleString()} credits
          </div>
          <div style={{ color: "var(--ink-mute)", fontSize: 12, letterSpacing: "0.06em" }}>
            That's about {Math.floor(selected.credits / 100)} images at 2K, or {Math.floor(selected.credits / 500)} five-second video clips.
          </div>
          {/* Plain claim rather than a trust badge. It is verifiably true: checkout
              is Stripe-hosted, there is no card field anywhere in the app, and we
              store only Stripe customer and subscription ids. A sentence someone
              can check beats a seal they do not recognise. */}
          <div style={{
            color: "var(--ink-mute)", fontSize: 12, lineHeight: 1.55,
            marginTop: 6, maxWidth: 420,
          }}>
            Payments are handled by Stripe. Your card details never touch our servers.
          </div>
        </div>
      </section>
      </div>

      <window.PSEnterprise />

      {tweaks.showBeforeAfter && <window.BeforeAfter />}

      {tweaks.showCompare && (
        <window.ComparisonTable rows={COMPARISON_ROWS} />
      )}

      {tweaks.showTestimonials && <window.Testimonials items={TESTIMONIALS} />}

      {tweaks.showCompetitors && (
        <window.CompetitorTable rows={COMPETITORS.rows} cols={COMPETITORS.cols} />
      )}

      <window.FAQ items={window.FAQ_ITEMS} />

      <window.FooterCTA />
    </div>
  );
}

// ----- new clearer card —- generation count front and center -----

function PlainerCard({ plan, mode, selected, onSelect, expanded, onToggleExpand, showGenerations }) {
  const dark = selected;
  const showMo = mode === "plans";

  // parse "10 × 2K / or 5 × 4K" → { hi: 10, lo: 5 }
  const imgs2K = parseInt((plan.images.match(/(\d+)\s*×\s*2K/) || [0,0])[1], 10);
  const imgs4K = parseInt((plan.images.match(/(\d+)\s*×\s*4K/) || [0,0])[1], 10);
  const vidsStd = parseInt((plan.videos.match(/(\d+)\s*standard/) || [0,0])[1], 10);
  const vidsPrem = parseInt((plan.videos.match(/(\d+)\s*premium/) || [0,0])[1], 10);

  return (
    <div
      onClick={onSelect}
      className={dark ? "pp-plan is-on" : "pp-plan"}
      style={{
        position: "relative",
        background: dark ? "var(--ink)" : "var(--card)",
        color: dark ? "var(--on-dark)" : "var(--ink)",
        borderRadius: "var(--radius-card)",
        padding: "30px 26px 22px",
        cursor: "pointer",
        transition: "transform 280ms cubic-bezier(.2,.7,.2,1), box-shadow 280ms ease",
        transform: dark ? "translateY(-10px)" : "translateY(0)",
        boxShadow: dark ? "0 24px 60px -24px rgba(39,36,28,0.45)" : "none",
        display: "flex",
        flexDirection: "column",
        gap: 18,
      }}
    >
      <div
        style={{
          fontFamily: "La Villa",
          fontSize: 11,
          letterSpacing: "0.22em",
          textTransform: "uppercase",
          fontWeight: 500,
          color: dark ? "var(--on-dark-soft)" : "var(--ink-soft)",
        }}
      >
        {plan.name}
      </div>

      <div style={{ display: "flex", alignItems: "baseline", gap: 6 }}>
        <span className="num" style={{ fontSize: 76, lineHeight: 0.95, letterSpacing: "-0.04em" }}>
          ${plan.price}
        </span>
        {showMo && (
          <span style={{ fontSize: 16, color: dark ? "var(--on-dark-soft)" : "var(--ink-soft)" }}>
            /mo
          </span>
        )}
      </div>

      <div>
        <div style={{ display: "flex", alignItems: "baseline", gap: 10 }}>
          <span className="num" style={{ fontSize: 22, letterSpacing: "-0.02em" }}>
            {plan.credits.toLocaleString()}
          </span>
          <span
            style={{
              fontSize: 11,
              letterSpacing: "0.22em",
              textTransform: "uppercase",
              color: dark ? "var(--on-dark-soft)" : "var(--ink-soft)",
            }}
          >
            credits
          </span>
        </div>
        <div style={{ marginTop: 8, fontSize: 14, color: dark ? "var(--on-dark)" : "var(--ink-soft)" }}>
          {plan.blurb}
        </div>
      </div>

      {showGenerations && (
        <div
          style={{
            background: dark ? "rgba(239,233,220,0.08)" : "rgba(39,36,28,0.04)",
            border: dark ? "1px solid rgba(239,233,220,0.14)" : "1px solid var(--card-line)",
            borderRadius: 12,
            padding: "14px 14px 12px",
            display: "flex",
            flexDirection: "column",
            gap: 10,
          }}
        >
          <div
            style={{
              fontSize: 10,
              letterSpacing: "0.22em",
              textTransform: "uppercase",
              fontWeight: 600,
              opacity: 0.7,
            }}
          >
            That's about
          </div>
          <GenLine label="Images, 2K" value={imgs2K} suffix="generations" dark={dark} />
          <GenLine label="Or images, 4K" value={imgs4K} suffix="generations" dark={dark} muted />
          <GenLine label="Or video clips, 5s" value={vidsStd} suffix="clips" dark={dark} muted />
        </div>
      )}

      <div style={{ flex: 1 }} />

      <div
        style={{
          borderTop: dark ? "1px solid rgba(239,233,220,0.18)" : "1px solid var(--card-line)",
          paddingTop: 14,
          display: "flex",
          flexDirection: "column",
          gap: 10,
        }}
      >
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
          <span
            style={{
              fontSize: 11,
              letterSpacing: "0.22em",
              textTransform: "uppercase",
              fontWeight: 500,
            }}
          >
            {selected ? "Selected" : "Select"}
          </span>
          <RadioMark checked={selected} dark={dark} />
        </div>
        <button
          onClick={(e) => {
            e.stopPropagation();
            onToggleExpand();
          }}
          style={{
            display: "flex",
            justifyContent: "space-between",
            alignItems: "center",
            width: "100%",
            color: "inherit",
            cursor: "pointer",
            background: "transparent",
            border: 0,
            padding: 0,
            outline: "none",
            font: "inherit",
          }}
        >
          <span
            style={{
              fontSize: 11,
              letterSpacing: "0.22em",
              textTransform: "uppercase",
              fontWeight: 500,
              opacity: 0.85,
            }}
          >
            {expanded ? "Hide details" : "Full breakdown"}
          </span>
          <span style={{ fontSize: 13, opacity: 0.7 }}>{expanded ? "↑" : "↓"}</span>
        </button>
        <div
          style={{
            display: "grid",
            gridTemplateRows: expanded ? "1fr" : "0fr",
            transition: "grid-template-rows 320ms cubic-bezier(.2,.7,.2,1)",
          }}
        >
          <div style={{ overflow: "hidden" }}>
            <div style={{ paddingTop: 12, display: "flex", flexDirection: "column", gap: 9, fontSize: 13 }}>
              <KV k="Billing" v={mode === "plans" ? "Monthly" : "One-time"} />
              <KV k="Per 100 credits" v={`$${plan.perHundred.toFixed(2)}`} />
              <KV k="2K images" v={`${imgs2K} generations`} />
              <KV k={mode === "plans" ? "Cancel" : "Expires"} v={mode === "plans" ? plan.cancel : plan.expires} />
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

function GenLine({ label, value, suffix, dark, muted }) {
  return (
    <div style={{ display: "flex", alignItems: "baseline", justifyContent: "space-between", opacity: muted ? 0.78 : 1 }}>
      <span style={{ fontSize: 12, opacity: 0.75 }}>{label}</span>
      <span style={{ fontFamily: "La Villa" }}>
        <span className="num" style={{ fontSize: 18, letterSpacing: "-0.02em" }}>{value}</span>
        <span style={{ fontSize: 11, marginLeft: 6, opacity: 0.7, letterSpacing: "0.04em" }}>{suffix}</span>
      </span>
    </div>
  );
}

function KV({ k, v }) {
  return (
    <div style={{ display: "flex", justifyContent: "space-between", gap: 12 }}>
      <span style={{ opacity: 0.7 }}>{k}</span>
      <span style={{ textAlign: "right" }}>{v}</span>
    </div>
  );
}

function RadioMark({ checked, dark }) {
  return (
    <span
      style={{
        width: 18,
        height: 18,
        borderRadius: "50%",
        border: `1.5px solid ${dark ? "var(--on-dark)" : "var(--ink)"}`,
        display: "inline-flex",
        alignItems: "center",
        justifyContent: "center",
      }}
    >
      <span
        style={{
          width: 8,
          height: 8,
          borderRadius: "50%",
          background: checked ? (dark ? "var(--on-dark)" : "var(--ink)") : "transparent",
          transition: "background 160ms ease",
        }}
      />
    </span>
  );
}

// Exported on window — Pricing.html mounts <PricingApp /> inside its own App
// shell so the page can sit alongside PSNav + PSFooter like the other landing
// sub-pages. The original handoff rendered straight into #app for the
// embed preview; that path is dead now.
window.PricingApp = PricingApp;
