/* global React, Icon, Footer, SiteHeader */
// "Unified Orders vs <competitor>" pages, and the compare hub.
// Driven entirely by compare-features.js (window.UO_FEATURE_LIST) and compare-vendors.js (window.UO_VENDORS).
// Add a module or a vendor in those files and every page updates. See the header comments there.

const { useState: useStateCp, useMemo: useMemoCp } = React;

const ST = {
  y: { sym: "✓", label: "Yes",          dot: "bg-green-600 text-white",  txt: "text-green-800" },
  p: { sym: "◐", label: "Partly",       dot: "bg-amber-400 text-stone-900", txt: "text-amber-800" },
  n: { sym: "✗", label: "Not offered",  dot: "bg-stone-300 text-stone-700", txt: "text-stone-600" },
  u: { sym: "?",      label: "Not confirmed", dot: "bg-stone-100 text-stone-500 border border-stone-300", txt: "text-stone-500" },
};
const STATUS_DETAIL = {
  y: "Full capability",
  p: "Partial, an add-on, or needs another tool",
  n: "Not offered, as far as we can find",
  u: "We could not confirm this",
};

function Dot({ s, size = 22 }) {
  const t = ST[s] || ST.u;
  return (
    <span title={STATUS_DETAIL[s] || ""} aria-label={t.label}
      className={"inline-flex items-center justify-center rounded-full font-bold flex-none " + t.dot}
      style={{ width: size, height: size, fontSize: Math.round(size * 0.55) }}>{t.sym}</span>
  );
}

function allModules() {
  const out = [];
  (window.UO_FEATURE_LIST?.groups || []).forEach((g) => g.modules.forEach((m) => out.push({ ...m, group: g.title, groupId: g.id })));
  return out;
}
function isNewModule(m) {
  if (!m.added) return false;
  return (Date.now() - new Date(m.added + "T12:00:00").getTime()) / 86400000 <= 60;
}
function scoreOf(v, id) { return (v.scores && v.scores[id]) || "u"; }
function tally(v) {
  const t = { y: 0, p: 0, n: 0, u: 0 };
  allModules().forEach((m) => { t[scoreOf(v, m.id)]++; });
  return t;
}
function vendorBySlug(slug) { return (window.UO_VENDORS?.vendors || []).find((v) => v.slug === slug); }

function NewBadge() {
  return <span className="text-[10.5px] font-bold px-1.5 py-0.5 rounded-full bg-green-100 text-green-800 align-middle ml-2">New</span>;
}
function OnlyTag() {
  return <span className="text-[10px] font-bold px-1.5 py-0.5 rounded bg-orange-100 text-orange-800 whitespace-nowrap">Only here</span>;
}

function Eyebrow({ children }) {
  return <span className="text-[11px] uppercase tracking-[0.18em] font-semibold text-orange-700">{children}</span>;
}
function H2({ children, sub }) {
  return (
    <div className="max-w-3xl">
      <h2 className="font-bold tracking-tight text-stone-900 mt-2" style={{ fontSize: "clamp(26px, 3vw, 38px)", lineHeight: 1.1, letterSpacing: "-0.02em" }}>{children}</h2>
      {sub && <p className="text-stone-600 mt-3 text-[16px] leading-relaxed">{sub}</p>}
    </div>
  );
}

function Legend() {
  return (
    <div className="flex flex-wrap gap-x-5 gap-y-2 text-[13px] text-stone-700">
      {["y", "p", "n", "u"].map((k) => (
        <span key={k} className="inline-flex items-center gap-2"><Dot s={k} size={18} />{STATUS_DETAIL[k]}</span>
      ))}
    </div>
  );
}

// ─── A single capability card (what you gain) ───────────────────────────────
function GainCard({ m, vs }) {
  return (
    <div className="bg-white border border-stone-200 rounded-2xl p-5 flex flex-col">
      <div className="flex items-start justify-between gap-3">
        <h3 className="font-semibold text-stone-900 text-[16.5px] tracking-tight leading-snug">{m.title}{isNewModule(m) && <NewBadge />}</h3>
        <span className="flex items-center gap-1.5 flex-none text-[11.5px] text-stone-600" title={STATUS_DETAIL[vs]}>
          <Dot s={vs} size={18} /> {ST[vs].label}
        </span>
      </div>
      <p className="text-stone-600 text-[14px] mt-1.5 leading-snug">{m.summary}</p>
      <ul className="mt-3 pt-3 border-t border-dashed border-stone-200 space-y-1.5 text-[13.5px] text-stone-700">
        {m.subs.slice(0, 4).map((s) => (
          <li key={s.t} className="flex gap-2 items-start">
            <span className="mt-[7px] w-1.5 h-1.5 rounded-full bg-orange-500 flex-none"></span>
            <span>{s.t} {s.only && <OnlyTag />}</span>
          </li>
        ))}
      </ul>
      {m.link && <a href={m.link} className="mt-auto pt-3 text-[13px] font-semibold text-orange-700 hover:text-orange-800">See how it works &rarr;</a>}
    </div>
  );
}

// ─── Full table for one vendor ──────────────────────────────────────────────
function VendorTable({ v }) {
  const [filter, setFilter] = useStateCp("all");
  const [open, setOpen] = useStateCp({});
  const groups = window.UO_FEATURE_LIST.groups;
  const keep = (m) => {
    const s = scoreOf(v, m.id);
    if (filter === "lead") return s === "n" || s === "p" || s === "u";
    if (filter === "match") return s === "y";
    return true;
  };
  return (
    <section className="py-16 border-t border-stone-200" id="table">
      <div className="max-w-7xl mx-auto px-6">
        <Eyebrow>Feature by feature</Eyebrow>
        <H2 sub={"Every capability Unified Orders has, checked against " + v.name + ". Tap a row to see what it covers."}>The full comparison</H2>
        <div className="mt-6 flex flex-wrap items-center justify-between gap-4">
          <div className="inline-flex rounded-lg border border-stone-300 bg-white p-0.5 text-[13px]" role="group" aria-label="Filter">
            {[["all", "Everything"], ["lead", "Where we go further"], ["match", "Where " + v.short + " matches us"]].map(([k, l]) => (
              <button key={k} type="button" onClick={() => setFilter(k)} aria-pressed={filter === k}
                className={"px-3 py-1.5 rounded-md font-medium transition-colors " + (filter === k ? "bg-stone-900 text-white" : "text-stone-700 hover:bg-stone-100")}>{l}</button>
            ))}
          </div>
          <Legend />
        </div>

        <div className="mt-6 bg-white border border-stone-200 rounded-2xl overflow-hidden">
          <div className="grid grid-cols-[minmax(0,1fr)_88px_88px] sm:grid-cols-[minmax(0,1fr)_120px_120px] bg-stone-100 text-[12px] uppercase tracking-wider text-stone-600 font-semibold">
            <div className="px-4 py-3">Capability</div>
            <div className="px-2 py-3 text-center text-orange-700">Unified Orders</div>
            <div className="px-2 py-3 text-center truncate">{v.short}</div>
          </div>
          {groups.map((g) => {
            const rows = g.modules.filter(keep);
            if (!rows.length) return null;
            return (
              <div key={g.id}>
                <div className="px-4 py-2 bg-stone-50 border-t border-stone-200 text-[11px] uppercase tracking-[0.14em] font-semibold text-stone-600">{g.title}</div>
                {rows.map((m) => {
                  const s = scoreOf(v, m.id);
                  const isOpen = !!open[m.id];
                  return (
                    <div key={m.id} className="border-t border-stone-100">
                      <button type="button" aria-expanded={isOpen} onClick={() => setOpen({ ...open, [m.id]: !isOpen })}
                        className="w-full grid grid-cols-[minmax(0,1fr)_88px_88px] sm:grid-cols-[minmax(0,1fr)_120px_120px] items-center text-left hover:bg-orange-50/40 transition-colors">
                        <div className="px-4 py-3">
                          <div className="font-medium text-stone-900 text-[14.5px] leading-snug">{m.title}{isNewModule(m) && <NewBadge />}</div>
                          <div className="text-[13px] text-stone-600 leading-snug mt-0.5">{m.summary}</div>
                        </div>
                        <div className="flex justify-center"><Dot s="y" /></div>
                        <div className="flex flex-col items-center gap-0.5"><Dot s={s} /><span className={"text-[11px] " + ST[s].txt}>{ST[s].label}</span></div>
                      </button>
                      {isOpen && (
                        <div className="px-4 pb-4 pt-1 bg-stone-50/60">
                          <ul className="grid sm:grid-cols-2 gap-x-6 gap-y-1.5 text-[13.5px] text-stone-700">
                            {m.subs.map((x) => (
                              <li key={x.t} className="flex gap-2 items-start"><span className="mt-[7px] w-1.5 h-1.5 rounded-full bg-orange-500 flex-none"></span><span>{x.t} {x.only && <OnlyTag />}</span></li>
                            ))}
                          </ul>
                          {m.link && <a href={m.link} className="inline-block mt-2 text-[13px] font-semibold text-orange-700 hover:text-orange-800">Read more &rarr;</a>}
                        </div>
                      )}
                    </div>
                  );
                })}
              </div>
            );
          })}
        </div>
        <p className="text-[12.5px] text-stone-600 mt-4 max-w-3xl leading-relaxed">
          Checked against public product pages and documentation, {window.UO_VENDORS.checked}. A ? means we could not confirm it either way, so we do not claim it. Software changes quickly: if you spot something out of date, email <a className="underline" href="mailto:hello@unifiedorders.com">hello@unifiedorders.com</a> and we will correct it.
        </p>
      </div>
    </section>
  );
}

// ─── Vendor page ────────────────────────────────────────────────────────────
function VsHero({ v, t, total }) {
  const phone = window.UO_PHONE;
  return (
    <section className="pt-14 pb-12">
      <div className="max-w-7xl mx-auto px-6">
        <Eyebrow>Compare</Eyebrow>
        <h1 className="font-bold tracking-tight text-stone-900 mt-2" style={{ fontSize: "clamp(34px, 4.6vw, 56px)", lineHeight: 1.04, letterSpacing: "-0.03em" }}>
          Unified Orders vs {v.name}
        </h1>
        <p className="text-stone-600 mt-5 text-[18px] leading-relaxed max-w-3xl">
          {v.about} Unified Orders is the ecommerce operating system: orders, stock, listings, shipping, returns, accounting, messaging, phone and social in one place. Here is what you get on each side, feature by feature.
        </p>
        <div className="grid sm:grid-cols-2 gap-4 mt-8 max-w-3xl">
          <div className="rounded-2xl border-2 border-orange-300 bg-orange-50/60 p-5">
            <div className="text-[12px] uppercase tracking-wider font-semibold text-orange-700">Unified Orders</div>
            <div className="mt-1 text-stone-900"><span className="text-4xl font-bold tracking-tight">{total}</span><span className="text-stone-600"> of {total} capabilities</span></div>
            <div className="text-[13px] text-stone-700 mt-1">Every module in every plan.</div>
          </div>
          <div className="rounded-2xl border border-stone-200 bg-white p-5">
            <div className="text-[12px] uppercase tracking-wider font-semibold text-stone-600">{v.name}</div>
            <div className="mt-1 text-stone-900"><span className="text-4xl font-bold tracking-tight">{t.y}</span><span className="text-stone-600"> fully covered</span></div>
            <div className="text-[13px] text-stone-700 mt-1">{t.p} partly, {t.n} not offered{t.u ? ", " + t.u + " not confirmed" : ""}.</div>
          </div>
        </div>
        <div className="flex flex-wrap gap-3 mt-8">
          <a href="contact.html" className="px-5 py-3 rounded-lg bg-orange-600 text-white font-semibold hover:bg-orange-700 inline-flex items-center gap-2 transition-colors">Start free trial <Icon name="arrow" size={15} /></a>
          <a href="#table" className="px-5 py-3 rounded-lg border border-stone-300 bg-white text-stone-800 font-semibold hover:border-stone-400 transition-colors">See the full table</a>
          {phone && <a href={"tel:" + phone.tel} className="px-5 py-3 rounded-lg text-stone-800 font-semibold hover:text-orange-700 inline-flex items-center gap-2 transition-colors"><Icon name="phone" size={15} />{phone.display}</a>}
        </div>
      </div>
    </section>
  );
}

function VsGains({ v }) {
  const list = useMemoCp(() => {
    const rank = { n: 0, u: 1, p: 2, y: 9 };
    return allModules()
      .filter((m) => scoreOf(v, m.id) !== "y")
      .sort((a, b) => rank[scoreOf(v, a.id)] - rank[scoreOf(v, b.id)] || (b.added || "").localeCompare(a.added || ""));
  }, [v.slug]);
  const shown = list.slice(0, 9);
  if (!list.length) return null;
  return (
    <section className="py-16 border-t border-stone-200">
      <div className="max-w-7xl mx-auto px-6">
        <Eyebrow>What you gain</Eyebrow>
        <H2 sub={"The capabilities where " + v.short + " offers less than Unified Orders, or where we could not confirm it offers them."}>
          What {v.short} doesn&rsquo;t give you
        </H2>
        <div className="grid md:grid-cols-2 lg:grid-cols-3 gap-4 mt-8">
          {shown.map((m) => <GainCard key={m.id} m={m} vs={scoreOf(v, m.id)} />)}
        </div>
        {list.length > shown.length && (
          <p className="mt-5 text-[14px] text-stone-700">&hellip;and {list.length - shown.length} more in <a href="#table" className="font-semibold text-orange-700 hover:text-orange-800">the full table</a>.</p>
        )}
      </div>
    </section>
  );
}

function VsPricing({ v }) {
  return (
    <section className="py-16 border-t border-stone-200">
      <div className="max-w-7xl mx-auto px-6">
        <Eyebrow>Pricing</Eyebrow>
        <H2>How the pricing compares</H2>
        <div className="grid md:grid-cols-2 gap-5 mt-8 max-w-5xl">
          <div className="rounded-2xl border border-stone-200 bg-white p-6">
            <div className="text-[12px] uppercase tracking-wider font-semibold text-stone-600">{v.name}</div>
            <p className="text-stone-800 mt-2 text-[15.5px] leading-relaxed">{v.pricing}</p>
            <p className="text-[12.5px] text-stone-500 mt-3">From the vendor&rsquo;s public pricing, July 2026. Check their site for today&rsquo;s prices.</p>
          </div>
          <div className="rounded-2xl border-2 border-orange-300 bg-orange-50/60 p-6">
            <div className="text-[12px] uppercase tracking-wider font-semibold text-orange-700">Unified Orders</div>
            <p className="text-stone-900 mt-2 text-[15.5px] leading-relaxed">Plans start at <strong>&pound;199 a month</strong> for 2,000 orders. Every module is in every plan, and the price you sign up at is locked in for three years. Phone &amp; SMS is a bolt-on from &pound;10 a month.</p>
            <a href="pricing.html" className="inline-block mt-3 text-[14px] font-semibold text-orange-700 hover:text-orange-800">See pricing &rarr;</a>
          </div>
        </div>
      </div>
    </section>
  );
}

function VsStrengths({ v }) {
  const both = allModules().filter((m) => scoreOf(v, m.id) === "y");
  if (!both.length) return null;
  return (
    <section className="py-16 border-t border-stone-200">
      <div className="max-w-7xl mx-auto px-6">
        <Eyebrow>Fair play</Eyebrow>
        <H2 sub={v.bestFor}>Where {v.short} matches us</H2>
        <div className="flex flex-wrap gap-2 mt-6">
          {both.map((m) => <span key={m.id} className="px-3 py-1.5 rounded-full bg-white border border-stone-200 text-[13.5px] text-stone-800">{m.title}</span>)}
        </div>
        <p className="mt-4 text-[14.5px] text-stone-700 max-w-3xl leading-relaxed">If these are all you need today, {v.short} may do the job. Most sellers outgrow that list, which is where the rest of the table comes in.</p>
      </div>
    </section>
  );
}

function VsSwitch({ v }) {
  const steps = [
    ["Connect your stores", "We link your marketplaces and webstores and bring across your past orders, SKUs and customers."],
    ["Run both for as long as you like", "Orders stay in sync while you move over, so nothing is doubled or lost."],
    ["Switch off " + v.short, "Most sellers are up and running within a day and shut the old system once they see how much faster the daily work is."],
  ];
  return (
    <section className="py-16 border-t border-stone-200">
      <div className="max-w-7xl mx-auto px-6">
        <Eyebrow>Switching</Eyebrow>
        <H2>Moving from {v.short} to Unified Orders</H2>
        <ol className="grid md:grid-cols-3 gap-4 mt-8">
          {steps.map(([t, b], i) => (
            <li key={t} className="bg-white border border-stone-200 rounded-2xl p-5">
              <div className="w-8 h-8 rounded-full bg-stone-900 text-white font-bold text-[14px] flex items-center justify-center">{i + 1}</div>
              <div className="font-semibold text-stone-900 mt-3">{t}</div>
              <p className="text-[14px] text-stone-600 mt-1 leading-snug">{b}</p>
            </li>
          ))}
        </ol>
        <a href={v.switchHref || "migration.html"} className="inline-block mt-5 text-[14px] font-semibold text-orange-700 hover:text-orange-800">{v.switchHref ? "Read the full switch guide" : "See how migration works"} &rarr;</a>
      </div>
    </section>
  );
}

function VsFaq({ v, t, total }) {
  const items = [
    [`How does Unified Orders compare with ${v.name}?`, `Unified Orders covers all ${total} capabilities on this page. ${v.name} fully covers ${t.y} of them, partly covers ${t.p}, and does not offer ${t.n} as far as we can find${t.u ? ", with " + t.u + " we could not confirm" : ""}. The full table above shows each one.`],
    [`Is Unified Orders cheaper than ${v.name}?`, `Pricing models differ, so compare like for like. ${v.pricing} Unified Orders starts at £199 a month for 2,000 orders with every module included, and the price is locked for three years.`],
    [`Can I move from ${v.name} without losing orders?`, "Yes. We bring across your past orders, SKUs and customers, and the two systems can run side by side while you switch, so there are no doubled or lost orders."],
    ["Which marketplaces and platforms are supported?", "Every major marketplace and webstore, including Amazon, eBay, Shopify, Etsy, TikTok Shop, WooCommerce, Magento and BigCommerce, and every other platform you sell on."],
    ["Does Unified Orders replace other subscriptions?", "For most sellers, yes. Returns, listings, shipping, accounting, the helpdesk, social posting and the business phone are all built in, so there are fewer tools to pay for and fewer tabs to keep open."],
  ];
  return (
    <section className="py-16 border-t border-stone-200">
      <div className="max-w-4xl mx-auto px-6">
        <Eyebrow>Questions</Eyebrow>
        <H2>Common questions</H2>
        <div className="mt-6 divide-y divide-stone-200 border-y border-stone-200">
          {items.map(([q, a]) => (
            <details key={q} className="group py-4">
              <summary className="cursor-pointer list-none flex items-center justify-between gap-4 font-semibold text-stone-900 text-[16px]">{q}<span className="text-stone-500 group-open:rotate-180 transition-transform">&#8964;</span></summary>
              <p className="text-stone-700 mt-2 text-[15px] leading-relaxed">{a}</p>
            </details>
          ))}
        </div>
      </div>
    </section>
  );
}

function OtherComparisons({ currentSlug }) {
  const others = (window.UO_VENDORS?.vendors || []).filter((x) => x.slug !== currentSlug);
  return (
    <section className="py-12 border-t border-stone-200">
      <div className="max-w-7xl mx-auto px-6">
        <Eyebrow>More comparisons</Eyebrow>
        <div className="flex flex-wrap gap-2 mt-3">
          {others.map((o) => <a key={o.slug} href={"vs-" + o.slug + ".html"} className="px-3 py-1.5 rounded-full bg-white border border-stone-200 text-[13.5px] text-stone-800 hover:border-orange-400 hover:text-orange-700 transition-colors">vs {o.short}</a>)}
          <a href="compare.html" className="px-3 py-1.5 rounded-full bg-stone-900 text-white text-[13.5px] font-medium">All comparisons</a>
        </div>
      </div>
    </section>
  );
}

function CpCta({ v }) {
  const phone = window.UO_PHONE;
  return (
    <section className="py-16">
      <div className="max-w-7xl mx-auto px-6">
        <div className="rounded-3xl bg-stone-900 text-white p-8 md:p-12">
          <h2 className="font-bold tracking-tight" style={{ fontSize: "clamp(26px, 3vw, 38px)", lineHeight: 1.1, letterSpacing: "-0.02em" }}>{v ? "Try the operating system, not just another " + v.short + " alternative." : "See it with your own orders."}</h2>
          <p className="text-stone-300 mt-3 max-w-2xl text-[16px] leading-relaxed">Start a free trial and we will help you bring your orders and SKUs across. Most sellers are up and running within a day.</p>
          <div className="flex flex-wrap gap-3 mt-6">
            <a href="contact.html" className="px-5 py-3 rounded-lg bg-orange-500 text-white font-semibold hover:bg-orange-600 transition-colors">Start free trial</a>
            {phone && <a href={"tel:" + phone.tel} className="px-5 py-3 rounded-lg bg-white/10 border border-white/20 text-white font-semibold hover:bg-white/15 transition-colors">Call {phone.display}</a>}
          </div>
        </div>
      </div>
    </section>
  );
}

function ComparePage({ slug }) {
  const v = vendorBySlug(slug);
  if (!v || !window.UO_FEATURE_LIST) return <div className="p-10">Page not found.</div>;
  const total = allModules().length;
  const t = tally(v);
  return (
    <>
      <SiteHeader active="compare" cta={{ label: "Start free trial", href: "contact.html" }}
        breadcrumb={[{ label: "Compare", href: "compare.html" }, { label: "vs " + v.short }]} />
      <main>
        <VsHero v={v} t={t} total={total} />
        <VsGains v={v} />
        <VendorTable v={v} />
        <VsPricing v={v} />
        <VsStrengths v={v} />
        <VsSwitch v={v} />
        <VsFaq v={v} t={t} total={total} />
        <OtherComparisons currentSlug={v.slug} />
        <CpCta v={v} />
      </main>
      <Footer />
    </>
  );
}

// ─── Hub ────────────────────────────────────────────────────────────────────
function HubMatrix() {
  const vendors = window.UO_VENDORS.vendors;
  const groups = window.UO_FEATURE_LIST.groups;
  return (
    <section className="py-16 border-t border-stone-200" id="matrix">
      <div className="max-w-7xl mx-auto px-6">
        <Eyebrow>Side by side</Eyebrow>
        <H2 sub="Every capability against every competitor we compare. Click a name for the full page.">The whole market in one table</H2>
        <div className="mt-5"><Legend /></div>
        <div className="mt-6 overflow-x-auto bg-white border border-stone-200 rounded-2xl">
          <table className="min-w-[1100px] w-full text-[13px]">
            <thead>
              <tr className="bg-stone-100 text-[11.5px] uppercase tracking-wider text-stone-600">
                <th className="text-left font-semibold px-4 py-3 sticky left-0 bg-stone-100 z-10 min-w-[230px]">Capability</th>
                <th className="font-semibold px-2 py-3 text-orange-700">Unified Orders</th>
                {vendors.map((v) => <th key={v.slug} className="font-semibold px-2 py-3"><a className="hover:text-orange-700" href={"vs-" + v.slug + ".html"}>{v.short}</a></th>)}
              </tr>
            </thead>
            <tbody>
              {groups.map((g) => (
                <React.Fragment key={g.id}>
                  <tr><td colSpan={vendors.length + 2} className="px-4 py-2 bg-stone-50 border-t border-stone-200 text-[11px] uppercase tracking-[0.14em] font-semibold text-stone-600">{g.title}</td></tr>
                  {g.modules.map((m) => (
                    <tr key={m.id} className="border-t border-stone-100">
                      <td className="px-4 py-2.5 sticky left-0 bg-white z-10 text-stone-900 font-medium">{m.title}{isNewModule(m) && <NewBadge />}</td>
                      <td className="text-center px-2 py-2.5 bg-orange-50/50"><Dot s="y" size={20} /></td>
                      {vendors.map((v) => <td key={v.slug} className="text-center px-2 py-2.5"><Dot s={scoreOf(v, m.id)} size={20} /></td>)}
                    </tr>
                  ))}
                </React.Fragment>
              ))}
            </tbody>
          </table>
        </div>
      </div>
    </section>
  );
}

function HubEverything() {
  const groups = window.UO_FEATURE_LIST.groups;
  const total = allModules().length;
  return (
    <section className="py-16 border-t border-stone-200" id="everything">
      <div className="max-w-7xl mx-auto px-6">
        <Eyebrow>The full list</Eyebrow>
        <H2 sub="The master list every comparison is built from. When we ship a new module it is added here, and every comparison page picks it up.">Everything Unified Orders does: {total} capabilities</H2>
        <div className="mt-8 space-y-10">
          {groups.map((g) => (
            <div key={g.id}>
              <h3 className="font-semibold text-stone-900 text-[18px] tracking-tight">{g.title}</h3>
              <div className="grid md:grid-cols-2 lg:grid-cols-3 gap-4 mt-4">
                {g.modules.map((m) => (
                  <div key={m.id} className="bg-white border border-stone-200 rounded-2xl p-5">
                    <div className="font-semibold text-stone-900 text-[15.5px] leading-snug">{m.title}{isNewModule(m) && <NewBadge />}</div>
                    <p className="text-[13.5px] text-stone-600 mt-1 leading-snug">{m.summary}</p>
                    <ul className="mt-3 space-y-1 text-[13px] text-stone-700">
                      {m.subs.map((x) => <li key={x.t} className="flex gap-2 items-start"><span className="mt-[6px] w-1.5 h-1.5 rounded-full bg-orange-500 flex-none"></span><span>{x.t}</span></li>)}
                    </ul>
                    {m.link && <a href={m.link} className="inline-block mt-3 text-[13px] font-semibold text-orange-700 hover:text-orange-800">Learn more &rarr;</a>}
                  </div>
                ))}
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

function CompareHub() {
  const vendors = window.UO_VENDORS.vendors;
  const total = allModules().length;
  return (
    <>
      <SiteHeader active="compare" cta={{ label: "Start free trial", href: "contact.html" }} breadcrumb={[{ label: "Compare" }]} />
      <main>
        <section className="pt-14 pb-12">
          <div className="max-w-7xl mx-auto px-6">
            <Eyebrow>Compare</Eyebrow>
            <h1 className="font-bold tracking-tight text-stone-900 mt-2" style={{ fontSize: "clamp(34px, 4.6vw, 56px)", lineHeight: 1.04, letterSpacing: "-0.03em" }}>Unified Orders vs everyone else.</h1>
            <p className="text-stone-600 mt-5 text-[18px] leading-relaxed max-w-3xl">{total} capabilities, checked against the {vendors.length} platforms sellers most often compare us with. Pick the one you use today, or scan the whole market in one table.</p>
            <div className="flex flex-wrap gap-3 mt-7">
              <a href="#matrix" className="px-5 py-3 rounded-lg bg-stone-900 text-white font-semibold hover:bg-stone-800 transition-colors">See the whole table</a>
              <a href="#everything" className="px-5 py-3 rounded-lg border border-stone-300 bg-white text-stone-800 font-semibold hover:border-stone-400 transition-colors">Everything we do</a>
            </div>
          </div>
        </section>
        <section className="pb-16">
          <div className="max-w-7xl mx-auto px-6 grid sm:grid-cols-2 lg:grid-cols-3 gap-4">
            {vendors.map((v) => {
              const t = tally(v);
              return (
                <a key={v.slug} href={"vs-" + v.slug + ".html"} className="group bg-white border border-stone-200 rounded-2xl p-5 hover:border-orange-400 hover:shadow-lg hover:shadow-orange-500/10 transition-all">
                  <div className="font-semibold text-stone-900 text-[17px] tracking-tight">Unified Orders vs {v.short}</div>
                  <p className="text-[13.5px] text-stone-600 mt-1.5 leading-snug">{v.about}</p>
                  <div className="mt-4 flex items-center gap-3 text-[12.5px] text-stone-700">
                    <span className="inline-flex items-center gap-1.5"><Dot s="y" size={16} />{t.y}</span>
                    <span className="inline-flex items-center gap-1.5"><Dot s="p" size={16} />{t.p}</span>
                    <span className="inline-flex items-center gap-1.5"><Dot s="n" size={16} />{t.n}</span>
                    {t.u > 0 && <span className="inline-flex items-center gap-1.5"><Dot s="u" size={16} />{t.u}</span>}
                    <span className="ml-auto text-orange-700 font-semibold group-hover:translate-x-0.5 transition-transform">Compare &rarr;</span>
                  </div>
                </a>
              );
            })}
          </div>
        </section>
        <HubMatrix />
        <HubEverything />
        <CpCta v={null} />
      </main>
      <Footer />
    </>
  );
}

window.ComparePage = ComparePage;
window.CompareHub = CompareHub;
