/* global React */
/* Channels · Omnichannel in one platform · Channel Preference · Predictive analytics */

const chStyles = {
  section: {
    background: "var(--k-cotton)", color: "var(--k-charcoal)",
    padding: "140px 56px 160px",
    borderTop: "1px solid var(--k-stone)",
  },
  inner: { maxWidth: 1480, margin: "0 auto" },
  head: { textAlign: "center", maxWidth: 1040, margin: "0 auto 56px" },
  eyebrow: { fontSize: 11, letterSpacing: "0.22em", textTransform: "uppercase", color: "var(--k-poppy)", marginBottom: 24, fontWeight: 600 },
  title: { fontFamily: "var(--serif)", fontWeight: 400, fontSize: "clamp(36px, 4.5vw, 64px)", lineHeight: 1.1, letterSpacing: "-0.01em", margin: 0, color: "var(--k-charcoal)" },
  sub: { marginTop: 24, fontSize: 17, lineHeight: 1.6, color: "var(--k-muted)", maxWidth: 760, marginLeft: "auto", marginRight: "auto" },

  /* Phone grid */
  grid: { display: "grid", gridTemplateColumns: "repeat(5, 1fr)", gap: 24, alignItems: "start", marginBottom: 96 },
  col: { display: "flex", flexDirection: "column", alignItems: "center", gap: 14 },
  label: { fontSize: 14, fontWeight: 600, color: "var(--k-charcoal)", textAlign: "center" },
  role: { fontSize: 11, letterSpacing: "0.14em", color: "var(--k-muted)", textTransform: "uppercase", textAlign: "center", fontWeight: 600 },
  phone: {
    width: "100%", aspectRatio: "9 / 19",
    background: "var(--k-cotton)",
    borderRadius: 28, border: "8px solid #2a2a2e",
    boxShadow: "0 18px 40px rgba(22,24,44,0.18), 0 0 0 1px var(--k-stone)",
    overflow: "hidden", position: "relative", color: "var(--k-charcoal)",
  },
  notch: { position: "absolute", top: 6, left: "50%", transform: "translateX(-50%)", width: 60, height: 14, background: "#2a2a2e", borderRadius: 999, zIndex: 4 },

  /* === Channel Preference === */
  prefBlock: {
    background: "var(--nb-cream-2)",
    border: "1px solid var(--k-stone)",
    borderRadius: 16,
    padding: 48,
    marginBottom: 32,
  },
  prefHead: { display: "grid", gridTemplateColumns: "1.1fr 1fr", gap: 64, alignItems: "end", marginBottom: 40 },
  prefEye: { fontSize: 11, letterSpacing: "0.22em", textTransform: "uppercase", color: "var(--k-poppy)", marginBottom: 16, fontWeight: 700 },
  prefT: { fontFamily: "var(--serif)", fontSize: "clamp(28px, 3.2vw, 44px)", lineHeight: 1.15, margin: 0, fontWeight: 400, letterSpacing: "-0.01em", color: "var(--k-charcoal)" },
  prefSub: { fontSize: 14, lineHeight: 1.65, color: "var(--k-muted)", maxWidth: 480 },

  prefRow: {
    display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 16,
  },
  prefCard: {
    background: "var(--k-cotton)",
    border: "1px solid var(--k-stone)",
    borderRadius: 10,
    padding: "22px 22px 26px",
    display: "flex", flexDirection: "column", gap: 12,
  },
  prefAvatar: {
    width: 40, height: 40, borderRadius: 999,
    background: "var(--k-poppy)", color: "var(--k-cotton)",
    display: "flex", alignItems: "center", justifyContent: "center",
    fontFamily: "var(--serif)", fontSize: 18, fontWeight: 500,
  },
  prefName: { fontSize: 14, fontWeight: 700, color: "var(--k-charcoal)" },
  prefMeta: { fontSize: 11, color: "var(--k-muted)", marginTop: 2 },
  prefBars: { display: "flex", flexDirection: "column", gap: 5, marginTop: 6 },
  prefBarRow: { display: "grid", gridTemplateColumns: "60px 1fr 32px", gap: 10, alignItems: "center", fontSize: 10 },
  prefBarLab: { color: "var(--k-muted)", letterSpacing: "0.08em", textTransform: "uppercase", fontWeight: 600 },
  prefBar: { height: 5, background: "rgba(35,33,33,0.08)", borderRadius: 3, overflow: "hidden" },
  prefBarFill: (pct, color) => ({ width: pct + "%", height: "100%", background: color, borderRadius: 3 }),
  prefBarVal: { color: "var(--k-charcoal)", fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace", fontSize: 10, textAlign: "right" },
  prefPick: {
    marginTop: 10, paddingTop: 12,
    borderTop: "1px dashed var(--k-stone)",
    fontSize: 11, lineHeight: 1.5,
    color: "var(--k-muted)",
  },
  prefPickT: { color: "var(--k-poppy)", fontWeight: 700, letterSpacing: "0.06em" },

  /* === Predictive analytics === */
  predBlock: {
    background: "linear-gradient(180deg, #F2E8F5 0%, #ECE0F0 100%)",
    border: "1px solid #C9B6F2",
    borderRadius: 16, padding: 48,
  },
  predHead: { display: "grid", gridTemplateColumns: "1.1fr 1fr", gap: 64, alignItems: "end", marginBottom: 40 },
  predEye: { fontSize: 11, letterSpacing: "0.22em", textTransform: "uppercase", color: "#7C5DBF", marginBottom: 16, fontWeight: 700 },
  predT: { fontFamily: "var(--serif)", fontSize: "clamp(28px, 3.2vw, 44px)", lineHeight: 1.15, margin: 0, fontWeight: 400, letterSpacing: "-0.01em", color: "var(--k-charcoal)" },
  predSub: { fontSize: 14, lineHeight: 1.65, color: "var(--k-muted)", maxWidth: 480 },

  predGrid: { display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 16 },
  predCard: {
    background: "var(--k-charcoal)",
    border: "1px solid #7C5DBF",
    borderRadius: 10, padding: "24px 24px 26px",
    display: "flex", flexDirection: "column", gap: 10,
    minHeight: 220,
  },
  predLab: { fontSize: 10, letterSpacing: "0.18em", textTransform: "uppercase", color: "#C9B6F2", fontWeight: 700 },
  predTitle: { fontFamily: "var(--serif)", fontSize: 22, lineHeight: 1.15, fontWeight: 400, margin: 0, color: "var(--k-cotton)" },
  predBody: { fontSize: 12.5, lineHeight: 1.55, color: "var(--k-stone)" },
  predMetric: {
    marginTop: "auto", paddingTop: 12, borderTop: "1px dashed rgba(124,93,191,0.3)",
    display: "flex", justifyContent: "space-between", alignItems: "baseline",
  },
  predMetricNum: { fontFamily: "var(--serif)", fontSize: 24, color: "#C9B6F2", fontWeight: 400, lineHeight: 1 },
  predMetricLab: { fontSize: 10, letterSpacing: "0.14em", color: "var(--k-stone)", textTransform: "uppercase", fontWeight: 700 },
};

/* === Equal-weight phone mocks (no FS/regulated emphasis) === */
function PhoneEmail() {
  return (
    <div style={{padding: "28px 12px 12px"}}>
      <div style={{aspectRatio: "1 / 0.85", background: "linear-gradient(180deg,#2563EB,#1E3A8A)", borderRadius: 4, marginBottom: 8, display: "flex", alignItems: "center", justifyContent: "center", color: "#fff", padding: 10, textAlign: "center"}}>
        <div style={{fontFamily: "var(--serif)", fontSize: 15, lineHeight: 1.15}}>The new<br/>season<br/>edit</div>
      </div>
      <div style={{background: "var(--k-charcoal)", color: "var(--k-cotton)", padding: "6px 10px", borderRadius: 3, fontSize: 9, fontWeight: 700, letterSpacing: "0.1em", textAlign: "center"}}>SHOP NOW</div>
      <div style={{fontSize: 8, marginTop: 8, color: "var(--k-muted)", textAlign: "center"}}>Picked for you</div>
      <div style={{display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 4, marginTop: 6}}>
        <div style={{aspectRatio: "1/1", background: "#3B82F6"}}/>
        <div style={{aspectRatio: "1/1", background: "#1E3A8A"}}/>
        <div style={{aspectRatio: "1/1", background: "#93C5FD"}}/>
      </div>
    </div>
  );
}
function PhoneSMS() {
  return (
    <div style={{padding: "32px 10px 10px"}}>
      <div style={{fontSize: 8, color: "var(--k-muted)", textAlign: "center", letterSpacing: "0.1em", marginBottom: 8}}>NOW</div>
      <div style={{background: "#E5E5EA", padding: "10px 12px", borderRadius: "12px 12px 12px 2px", fontSize: 10, lineHeight: 1.4, color: "var(--k-charcoal)"}}>
        Hi Margaret, this week&rsquo;s drop is in your size. Tap to view — link.nb/early
      </div>
      <div style={{fontSize: 7, marginTop: 6, color: "var(--k-muted)"}}>Reply STOP to opt out</div>
    </div>
  );
}
function PhoneWhatsApp() {
  return (
    <div style={{padding: "28px 0 0", background: "#E5DDD5", height: "100%"}}>
      <div style={{background: "#075E54", color: "var(--k-cotton)", fontSize: 9, padding: "8px 10px", display: "flex", gap: 6, alignItems: "center"}}>
        <span style={{width: 14, height: 14, borderRadius: 999, background: "var(--k-poppy)"}}/>
        <span>N Brown</span>
      </div>
      <div style={{padding: 10}}>
        <div style={{background: "var(--k-cotton)", padding: "8px 10px", borderRadius: "12px 12px 12px 2px", fontSize: 9, lineHeight: 1.45, marginBottom: 8}}>
          Hi Margaret, your saved item is back in 12. Need help with sizing?
        </div>
        <div style={{background: "#DCF8C6", padding: "6px 10px", borderRadius: "12px 12px 2px 12px", fontSize: 9, lineHeight: 1.4, marginLeft: "auto", maxWidth: "70%"}}>Yes please</div>
      </div>
    </div>
  );
}
function PhoneApp() {
  return (
    <div style={{padding: "28px 10px 10px", background: "var(--k-charcoal)", color: "var(--k-cotton)", height: "100%"}}>
      <div style={{fontSize: 9, color: "var(--k-stone)", letterSpacing: "0.1em", marginBottom: 8}}>APP NOTIFICATION</div>
      <div style={{fontFamily: "var(--serif)", fontSize: 17, lineHeight: 1.15, marginBottom: 8}}>Insider tier:<br/>1,820 points.</div>
      <div style={{fontSize: 9, color: "var(--k-stone)", marginBottom: 12, lineHeight: 1.4}}>You&rsquo;re 180 points from the next reward.</div>
      <div style={{background: "var(--k-poppy)", color: "var(--k-cotton)", padding: "8px 12px", borderRadius: 999, fontSize: 9, fontWeight: 700, textAlign: "center"}}>Open</div>
    </div>
  );
}
function PhoneWeb() {
  return (
    <div style={{padding: "28px 8px 8px"}}>
      <div style={{fontSize: 8, color: "var(--k-muted)", letterSpacing: "0.1em"}}>nbrown.co.uk</div>
      <div style={{fontFamily: "var(--serif)", fontSize: 14, marginTop: 8, color: "var(--k-charcoal)"}}>Welcome back, Margaret</div>
      <div style={{fontSize: 8, color: "var(--k-muted)", marginTop: 4}}>Insider tier · 1,820 points</div>
      <div style={{marginTop: 10, padding: 8, background: "var(--nb-cream)", borderRadius: 4, fontSize: 8, lineHeight: 1.3, color: "var(--k-charcoal)"}}>
        <strong>Picked for you</strong><br/>In your saved sizes.
      </div>
      <div style={{marginTop: 8, display: "grid", gridTemplateColumns: "1fr 1fr", gap: 4}}>
        <div style={{aspectRatio: "1/1", background: "#16A34A"}}/>
        <div style={{aspectRatio: "1/1", background: "#EAB308"}}/>
      </div>
    </div>
  );
}
function PhoneSocial() {
  return (
    <div style={{padding: "28px 0 0", background: "linear-gradient(180deg,#fce4ec,#f8b9d1)", height: "100%"}}>
      <div style={{padding: "8px 10px", display: "flex", alignItems: "center", gap: 6}}>
        <span style={{width: 14, height: 14, borderRadius: 999, background: "var(--k-cotton)"}}/>
        <span style={{fontSize: 9, color: "var(--k-charcoal)", fontWeight: 600}}>nbrown</span>
      </div>
      <div style={{aspectRatio: "1 / 0.9", background: "linear-gradient(135deg,#F97316,#7A2E3B)", margin: "0 6px", borderRadius: 4, display: "flex", alignItems: "center", justifyContent: "center", color: "#fff", fontFamily: "var(--serif)", fontSize: 12, padding: 8, textAlign: "center"}}>
        The new<br/>season<br/>is here
      </div>
      <div style={{padding: "8px 10px", fontSize: 9, color: "var(--k-charcoal)"}}>
        Join the rewards programme.
      </div>
    </div>
  );
}

const CHANNELS = [
  { name: "Email",     role: "Engage",    render: PhoneEmail },
  { name: "Text",      role: "Engage",    render: PhoneSMS },
  { name: "WhatsApp",  role: "Engage",    render: PhoneWhatsApp },
  { name: "Mobile app",role: "Engage",    render: PhoneApp },
  { name: "Social",    role: "Engage",    render: PhoneSocial },
];

const PREF_CUSTOMERS = [
  {
    initials: "MW", name: "Margaret W.", meta: "Insider · age 58 · Manchester",
    bars: [
      { lab: "Email",  pct: 82, val: "82%" },
      { lab: "SMS",    pct: 18, val: "18%" },
      { lab: "App",    pct: 12, val: "12%" },
      { lab: "Web",    pct: 64, val: "64%" },
    ],
    pickT: "Email",
    pickB: "Heavy email engagement, light SMS. Send-time model picked 09:00 — predicted open 28.4%.",
  },
  {
    initials: "AK", name: "Aisha K.", meta: "Welcome tier · age 24 · Birmingham",
    bars: [
      { lab: "Email",  pct: 22, val: "22%" },
      { lab: "SMS",    pct: 78, val: "78%" },
      { lab: "App",    pct: 68, val: "68%" },
      { lab: "Web",    pct: 41, val: "41%" },
    ],
    pickT: "SMS · App",
    pickB: "Strong mobile signal, low email engagement. Browse-abandonment flow defaults to SMS with app fallback.",
  },
  {
    initials: "TR", name: "Tom R.", meta: "Welcome tier · age 38 · Leeds",
    bars: [
      { lab: "Email",  pct: 44, val: "44%" },
      { lab: "SMS",    pct: 36, val: "36%" },
      { lab: "App",    pct: 8,  val: "8%"  },
      { lab: "WApp",   pct: 71, val: "71%" },
    ],
    pickT: "WhatsApp",
    pickB: "WhatsApp opt-in active, conversational replies. Channel picked for sizing and high-touch service.",
  },
  {
    initials: "DH", name: "Deborah H.", meta: "Insider · age 67 · Bristol",
    bars: [
      { lab: "Email",  pct: 64, val: "64%" },
      { lab: "SMS",    pct: 12, val: "12%" },
      { lab: "App",    pct: 4,  val: "4%"  },
      { lab: "Mail",   pct: 88, val: "88%" },
    ],
    pickT: "Catalogue + Email",
    pickB: "Strong direct-mail history. Email backed up with seasonal catalogue — never SMS, never app.",
  },
];

const PREDICTIVE = [
  {
    lab: "Predicted CLV",
    title: "Customer lifetime value.",
    body: "Modelled from order history, AOV, recency, frequency and behavioural signals. Drives VIP tiers, upper-funnel targeting, and acquisition bid caps.",
    num: "£4,820",
    metricLab: "Margaret W. · top 8%",
  },
  {
    lab: "Predicted churn",
    title: "Risk of leaving.",
    body: "Probability a profile lapses in the next 90 days. Trigger win-back flows the moment the score crosses a threshold — not weeks after.",
    num: "0.18",
    metricLab: "Low risk · monitor",
  },
  {
    lab: "Next order date",
    title: "When they&rsquo;ll buy again.",
    body: "Predicted purchase window. Replenishment flows, reactivation campaigns and trade calendars all pivot off this score.",
    num: "~22d",
    metricLab: "Mid-cycle · stable",
  },
  {
    lab: "Send-time intelligence",
    title: "When they&rsquo;ll open.",
    body: "Best send time, per profile, based on historic open patterns. Set the campaign — Klaviyo staggers delivery across the audience.",
    num: "09:00",
    metricLab: "Local time · auto",
  },
];

function ChannelShowcase() {
  return (
    <section id="channels" style={chStyles.section} data-screen-label="08 Channels · Omnichannel">
      <div style={chStyles.inner}>
        <div style={{margin: "0 auto 80px", maxWidth: 1480}}>
          <img
            src={window.__asset("omniChannel", "assets/omnichannel-orchestration.png")}
            alt="Omnichannel orchestration — one customer profile powers best-in-class channels: Email, Text, WhatsApp, Mobile app, Social"
            style={{width: "100%", height: "auto", display: "block", borderRadius: 16, border: "1px solid var(--k-stone)"}}
          />
        </div>

        {/* === Channel preference === */}
        <div style={chStyles.prefBlock}>
          <div style={chStyles.prefHead}>
            <div>
              <div style={chStyles.prefEye}>Channel preference · learnt, per profile</div>
              <h3 style={chStyles.prefT}>
                Pick the right channel,<br/>
                <span className="serif-i" style={{color: "var(--k-poppy)"}}>not the same channel</span>.
              </h3>
            </div>
            <p style={chStyles.prefSub}>
              Klaviyo&rsquo;s channel-affinity model learns each customer&rsquo;s
              preferred channel from engagement patterns. Same campaign, same flow
              — different channel for each profile. No customer over-served on
              one channel, no customer missed on another.
            </p>
          </div>

          <div style={chStyles.prefRow}>
            {PREF_CUSTOMERS.map(c => (
              <div key={c.name} style={chStyles.prefCard}>
                <div style={{display: "flex", alignItems: "center", gap: 12}}>
                  <div style={chStyles.prefAvatar}>{c.initials}</div>
                  <div>
                    <div style={chStyles.prefName}>{c.name}</div>
                    <div style={chStyles.prefMeta}>{c.meta}</div>
                  </div>
                </div>
                <div style={chStyles.prefBars}>
                  {c.bars.map(b => (
                    <div key={b.lab} style={chStyles.prefBarRow}>
                      <div style={chStyles.prefBarLab}>{b.lab}</div>
                      <div style={chStyles.prefBar}>
                        <div style={chStyles.prefBarFill(b.pct, "var(--k-poppy)")}/>
                      </div>
                      <div style={chStyles.prefBarVal}>{b.val}</div>
                    </div>
                  ))}
                </div>
                <div style={chStyles.prefPick}>
                  <div style={chStyles.prefPickT}>→ AI picks: {c.pickT}</div>
                  <div style={{marginTop: 4}}>{c.pickB}</div>
                </div>
              </div>
            ))}
          </div>
        </div>

        {/* === Predictive analytics === */}
        <div style={chStyles.predBlock}>
          <div style={chStyles.predHead}>
            <div>
              <div style={chStyles.predEye}>Predictive analytics · grounded in real-time events</div>
              <h3 style={chStyles.predT}>
                Four scores on every profile.<br/>
                <span className="serif-i" style={{color: "#C9B6F2"}}>Decisions made for you</span>.
              </h3>
            </div>
            <p style={chStyles.predSub}>
              CLV, churn, next-order date, send-time intelligence. Computed live
              from the event stream — and available as targetable conditions in
              every segment and flow. The decisioning layer underneath every
              channel.
            </p>
          </div>

          <div style={chStyles.predGrid}>
            {PREDICTIVE.map(p => (
              <div key={p.lab} style={chStyles.predCard}>
                <div style={chStyles.predLab}>{p.lab}</div>
                <h4 style={chStyles.predTitle} dangerouslySetInnerHTML={{__html: p.title}}/>
                <div style={chStyles.predBody}>{p.body}</div>
                <div style={chStyles.predMetric}>
                  <span style={chStyles.predMetricNum}>{p.num}</span>
                  <span style={chStyles.predMetricLab}>{p.metricLab}</span>
                </div>
              </div>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}
