/* global React */

// ============================================================
// Video CDN, Outcomes (4 benefits) + mid CTA
// Feature card: live concurrent viewer graph
// ============================================================
const VD_BEN_CSS = `
.VD-ben{position:relative;background:linear-gradient(180deg,#FAFAFE 0%,#F6F4FB 100%);padding:var(--section-pad-y-d) 0;font-family:'Inter','Noto Sans HK','Noto Sans TC',sans-serif;color:#0F2A47;border-top:1px solid rgba(15,42,71,0.06);border-bottom:1px solid rgba(15,42,71,0.06)}
.VD-ben-head{max-width:820px;margin-bottom:52px}
.VD-ben-h2{margin:0;font-size:clamp(36px,4.2vw,56px);line-height:1.08;font-weight:700;letter-spacing:-1.6px;color:#0F2A47;text-wrap:balance}
.VD-ben-h2 .accent{background:linear-gradient(135deg,#A855F7 0%,#7C3AED 100%);-webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent;color:transparent}
.VD-ben-lede{margin-top:22px;font-size:17px;line-height:1.7;color:#475569;max-width:600px;text-wrap:pretty}

.VD-ben-grid{display:grid;grid-template-columns:1.15fr 1fr;gap:24px;align-items:stretch}

/* Featured outcome */
.VD-feat{position:relative;background:radial-gradient(120% 120% at 100% 0%,#1A3A5A 0%,#0F2A47 65%);color:#fff;border-radius:24px;padding:44px 44px 36px;overflow:hidden;display:flex;flex-direction:column;gap:22px}
.VD-feat::before{content:'';position:absolute;top:-120px;right:-90px;width:340px;height:340px;background:radial-gradient(circle,rgba(167,139,250,0.32) 0%,transparent 70%);pointer-events:none}
.VD-feat-num{font-family:'Chakra Petch','Inter',sans-serif;font-size:13px;font-weight:600;letter-spacing:2.2px;color:#C4B5FD;text-transform:uppercase}
.VD-feat-h3{margin:0;font-size:32px;font-weight:700;letter-spacing:-.8px;line-height:1.18;color:#fff;text-wrap:balance;max-width:420px}
.VD-feat-h3 .accent{background:linear-gradient(135deg,#C4B5FD 0%,#A855F7 100%);-webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent;color:transparent}
.VD-feat-p{margin:0;font-size:15.5px;line-height:1.7;color:rgba(255,255,255,0.74);max-width:440px;text-wrap:pretty}

/* live-viewer area chart inside feature */
.VD-feat-chart{margin-top:auto;background:rgba(255,255,255,0.04);border:1px solid rgba(196,181,253,0.18);border-radius:14px;padding:22px 22px 18px;backdrop-filter:blur(2px)}
.VD-feat-chart-head{display:flex;justify-content:space-between;align-items:baseline;margin-bottom:8px;gap:12px}
.VD-feat-chart-lbl{font-family:'Chakra Petch','Inter',sans-serif;font-size:13px;font-weight:600;letter-spacing:1.6px;color:rgba(196,181,253,0.7);text-transform:uppercase}
.VD-feat-chart-v{font-family:'Chakra Petch','Inter',sans-serif;font-size:22px;font-weight:600;color:#C4B5FD;letter-spacing:-.4px;line-height:1;font-variant-numeric:tabular-nums;display:inline-flex;align-items:center;gap:8px}
.VD-feat-chart-v::before{content:'';width:7px;height:7px;border-radius:50%;background:#22C55E;box-shadow:0 0 0 0 rgba(34,197,94,0.55);animation:vdLivePulse 1.5s ease-in-out infinite}
@keyframes vdLivePulse{0%,100%{transform:scale(1);box-shadow:0 0 0 0 rgba(34,197,94,0.55)}50%{transform:scale(1.3);box-shadow:0 0 0 6px rgba(34,197,94,0)}}

.VD-feat-svg{width:100%;height:100px;display:block}
.VD-feat-axis{margin-top:6px;display:flex;justify-content:space-between;font-family:'Chakra Petch',monospace;font-size:9.5px;color:rgba(196,181,253,0.75);letter-spacing:.8px;text-transform:uppercase}

/* Secondary outcomes, compact stack */
.VD-sec{display:flex;flex-direction:column;gap:14px}
.VD-sec-it{position:relative;background:#fff;border:1px solid rgba(15,42,71,0.10);border-radius:16px;padding:22px 24px 22px 78px;transition:border-color .2s,transform .2s,box-shadow .2s}
.VD-sec-it:hover{border-color:#A855F7;box-shadow:0 12px 28px rgba(124,58,237,0.10);transform:translateY(-1px)}
.VD-sec-ic{position:absolute;left:24px;top:22px;width:38px;height:38px;border-radius:11px;background:linear-gradient(135deg,#F3EEFE 0%,#E7DEFB 100%);color:#7C3AED;display:flex;align-items:center;justify-content:center;box-shadow:inset 0 0 0 1px rgba(124,58,237,0.10)}
.VD-sec-ic svg{width:22px;height:22px}
.VD-sec-h3{margin:0;font-size:17px;font-weight:700;letter-spacing:-.2px;line-height:1.3;color:#0F2A47}
.VD-sec-p{margin:6px 0 0;font-size:14.5px;line-height:1.65;color:#475569;text-wrap:pretty}
.VD-sec-p b{color:#0F2A47;font-weight:600}

/* Mid CTA banner */
.VD-midcta{margin-top:48px;position:relative;background:#fff;border:1px solid rgba(124,58,237,0.18);border-radius:20px;padding:30px 36px;display:grid;grid-template-columns:1fr auto;gap:24px;align-items:center;overflow:hidden}
.VD-midcta::before{content:'';position:absolute;left:0;top:0;bottom:0;width:5px;background:linear-gradient(135deg,#A855F7 0%,#7C3AED 100%)}
.VD-midcta-text{padding-left:18px}
.VD-midcta-t{margin:0;font-size:22px;font-weight:700;color:#0F2A47;letter-spacing:-.4px;line-height:1.3;text-wrap:balance}
.VD-midcta-t .accent{background:linear-gradient(135deg,#A855F7 0%,#7C3AED 100%);-webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent;color:transparent}
.VD-midcta-s{margin:6px 0 0;font-size:14px;color:#64748b;font-family:'Chakra Petch','Inter',sans-serif;letter-spacing:.6px}
.VD-midcta-btn{display:inline-flex;align-items:center;gap:10px;padding:15px 28px;background:linear-gradient(135deg,#A855F7 0%,#7C3AED 100%);color:#fff;font-size:14.5px;font-weight:700;border-radius:999px;text-decoration:none;letter-spacing:.2px;box-shadow:0 8px 22px rgba(124,58,237,0.30);transition:all .15s;white-space:nowrap}
.VD-midcta-btn:hover{background:linear-gradient(135deg,#9333EA 0%,#6D28D9 100%);transform:translateY(-1px);box-shadow:0 12px 28px rgba(124,58,237,0.40)}

@media (max-width: 1024px){
  .VD-ben{padding:var(--section-pad-y-t) 0}
  .VD-ben-grid{grid-template-columns:1fr;gap:18px}
  .VD-feat-h3{font-size:28px}
}
@media (max-width: 640px){
  .VD-ben{padding:var(--section-pad-y-m) 0}
  .VD-ben-head{margin-bottom:40px}
  .VD-ben-h2{font-size:32px;letter-spacing:-1px}
  .VD-feat{padding:32px 26px 28px}
  .VD-feat-h3{font-size:26px}
  .VD-sec-it{padding:20px 20px 20px 70px}
  .VD-sec-ic{left:20px;top:20px;width:34px;height:34px}
  .VD-midcta{grid-template-columns:1fr;padding:22px 22px;gap:14px;margin-top:32px}
  .VD-midcta-text{padding-left:14px}
  .VD-midcta-t{font-size:17px;letter-spacing:-.3px;line-height:1.35}
  .VD-midcta-s{font-size:13px;letter-spacing:.4px}
  .VD-midcta-btn{justify-self:start;padding:12px 22px;font-size:13.5px}
}
`;

// Concurrent-viewer area chart, simulates a live event surge then plateau
function VDLiveChart() {
  // 20 points: ramp + surge + plateau
  const PTS = [40, 90, 180, 300, 520, 780, 920, 1010, 1080, 1140,
               1200, 1260, 1290, 1310, 1330, 1340, 1350, 1355, 1360, 1366];
  const max = 1400, w = 480, h = 100, pad = 4;
  const xStep = (w - pad * 2) / (PTS.length - 1);
  const toXY = (v, i) => [pad + i * xStep, h - pad - (v / max) * (h - pad * 2)];
  const path = PTS.map((v, i) => {
    const [x, y] = toXY(v, i);
    return (i ? 'L' : 'M') + x.toFixed(1) + ' ' + y.toFixed(1);
  }).join(' ');
  const area = path + ` L ${w - pad} ${h - pad} L ${pad} ${h - pad} Z`;
  const [lx, ly] = toXY(PTS[PTS.length - 1], PTS.length - 1);

  return (
    <svg className="VD-feat-svg" viewBox={`0 0 ${w} ${h}`} preserveAspectRatio="none" aria-hidden="true">
      <defs>
        <linearGradient id="vd-area" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#A855F7" stopOpacity="0.55" />
          <stop offset="100%" stopColor="#7C3AED" stopOpacity="0.02" />
        </linearGradient>
      </defs>
      {/* grid */}
      {[0.25, 0.5, 0.75].map((g) => (
        <line key={g} x1={pad} x2={w - pad} y1={h * g} y2={h * g}
          stroke="rgba(196,181,253,0.12)" strokeDasharray="2 4" />
      ))}
      <path d={area} fill="url(#vd-area)" />
      <path d={path} fill="none" stroke="#C4B5FD" strokeWidth="2" strokeLinejoin="round" strokeLinecap="round" />
      {/* live dot at end */}
      <circle cx={lx} cy={ly} r="9" fill="#22C55E" opacity="0.20">
        <animate attributeName="r" values="6;12;6" dur="1.6s" repeatCount="indefinite" />
      </circle>
      <circle cx={lx} cy={ly} r="3.5" fill="#22C55E" stroke="#fff" strokeWidth="1.5" />
    </svg>
  );
}

// ---- icons ----
const VdIcRevenue = () => <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M3 17 L8 12 L12 14 L17 8 L21 12" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" /><circle cx="17" cy="8" r="2" fill="currentColor" /><path d="M3 21 L21 21" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" opacity=".5" /></svg>;
const VdIcDevice = () => <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><rect x="2" y="6" width="14" height="10" rx="1.6" stroke="currentColor" strokeWidth="1.7" /><rect x="14" y="9" width="8" height="11" rx="1.4" stroke="currentColor" strokeWidth="1.7" fill="#fff" /><line x1="5" y1="20" x2="11" y2="20" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" /><circle cx="18" cy="17" r="0.9" fill="currentColor" /></svg>;
const VdIcShield = () => <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M12 3 L20 6 L20 12 Q20 18 12 21 Q4 18 4 12 L4 6 Z" stroke="currentColor" strokeWidth="1.8" strokeLinejoin="round" /><path d="M10 11 H14 V15 H10 Z M11 11 V9 a 1 1 0 0 1 2 0 V11" stroke="currentColor" strokeWidth="1.5" fill="none" strokeLinejoin="round" /></svg>;
const VdIcCoin = () => <svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><ellipse cx="12" cy="6" rx="8" ry="2.6" stroke="currentColor" strokeWidth="1.7" /><path d="M4 6v6c0 1.4 3.6 2.6 8 2.6s8-1.2 8-2.6V6" stroke="currentColor" strokeWidth="1.7" fill="none" /><path d="M4 12v6c0 1.4 3.6 2.6 8 2.6s8-1.2 8-2.6v-6" stroke="currentColor" strokeWidth="1.7" fill="none" /></svg>;

const VD_SECONDARY = [
  {
    icon: <VdIcDevice />,
    t: '觀眾體驗一致',
    p: '不論手機、平板、桌面或智能電視，不論 4G、5G 或 Wi-Fi，<b>觀眾都享受流暢觀看</b>，平均觀看時長與留存率隨之提升。',
  },
  {
    icon: <VdIcShield />,
    t: '版權內容受保護',
    p: '配備授權控制機制，<b>防止盜鏈與越區觀看</b>，保障內容投資與授權合約執行。',
  },
  {
    icon: <VdIcCoin />,
    t: '源站基建成本下降',
    p: '邊緣節點承接靜態與大流量影片資源，源站只承擔 origin 與動態邏輯，<b>毋須因觀眾增長頻繁擴容</b>。',
  },
];

function VideoBenefits() {
  return (
    <>
      <style>{VD_BEN_CSS}</style>
      <section className="VD-ben" data-screen-label="03 Outcomes">
        <div className="container">
          <div className="VD-ben-head">
            <h2 className="VD-ben-h2"><span className="accent">直播不斷線</span>，觀眾不離場</h2>
            <p className="VD-ben-lede">
              影片 CDN 不只是把訊號送到觀眾眼前。它直接影響你的訂閱、廣告收入、留存率，以及運營成本。
            </p>
          </div>

          <div className="VD-ben-grid">
            <div className="VD-feat">
              <h3 className="VD-feat-h3">突發流量自動承壓<span className="accent">，訂閱與廣告收入穩定</span></h3>
              <p className="VD-feat-p">
                觀看人數突發增長時，邊緣節點自動分散負載，源站只處理 origin pull。
                直播、賽事、帶貨日不再因擠塞中斷。
              </p>
              <div className="VD-feat-chart">
                <div className="VD-feat-chart-head">
                  <span className="VD-feat-chart-lbl">直播當日同時觀看人數</span>
                  <span className="VD-feat-chart-v">1,366,408</span>
                </div>
                <VDLiveChart />
                <div className="VD-feat-axis">
                  <span>T-30m</span><span>開始</span><span>T+30m</span><span>T+60m</span><span>NOW</span>
                </div>
              </div>
            </div>

            <div className="VD-sec">
              {VD_SECONDARY.map((s, i) => (
                <div key={i} className="VD-sec-it">
                  <div className="VD-sec-ic">{s.icon}</div>
                  <h3 className="VD-sec-h3">{s.t}</h3>
                  <p className="VD-sec-p" dangerouslySetInnerHTML={{ __html: s.p }} />
                </div>
              ))}
            </div>
          </div>

        </div>
      </section>
    </>
  );
}

window.VideoBenefits = VideoBenefits;
