/* global React */
const { useState: useVDEndState } = React;

// ============================================================
// Video CDN, Enquiry Form + FAQ + Final CTA
// Same chrome as HK end; copy specific to video / streaming.
// ============================================================
const VD_END_CSS = `
/* ---------- Enquiry Form ---------- */
.VD-enq{position:relative;background:#0F2A47;color:#fff;padding:var(--section-pad-y-d) 0;font-family:'Inter','Noto Sans HK','Noto Sans TC',sans-serif;overflow:hidden}
.VD-enq::before{content:'';position:absolute;top:-220px;right:-220px;width:600px;height:600px;background:radial-gradient(circle,rgba(167,139,250,0.18) 0%,transparent 70%);pointer-events:none}
.VD-enq::after{content:'';position:absolute;bottom:-220px;left:-220px;width:500px;height:500px;background:radial-gradient(circle,rgba(124,58,237,0.13) 0%,transparent 70%);pointer-events:none}

.VD-enq-inner{position:relative;display:grid;grid-template-columns:0.9fr 1.1fr;gap:72px;align-items:start}
.VD-enq-h2{margin:0;font-size:clamp(36px,4.2vw,56px);line-height:1.08;font-weight:700;letter-spacing:-1.6px;color:#fff;text-wrap:balance}
.VD-enq-h2 .accent{background:linear-gradient(135deg,#C4B5FD 0%,#A855F7 100%);-webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent;color:transparent}
.VD-enq-lede{margin-top:22px;font-size:16.5px;line-height:1.7;color:rgba(255,255,255,0.74);max-width:480px;text-wrap:pretty}

/* Use-case checklist (replaces meta bullets) */
.VD-enq-uses{margin-top:36px;display:grid;grid-template-columns:1fr;gap:8px;max-width:420px}
.VD-enq-use{display:grid;grid-template-columns:auto 1fr;gap:14px;align-items:center;padding:12px 14px;background:rgba(255,255,255,0.04);border:1px solid rgba(196,181,253,0.14);border-radius:12px;font-size:13.5px;color:rgba(255,255,255,0.82);transition:border-color .15s,background .15s}
.VD-enq-use .tick{width:22px;height:22px;border-radius:50%;background:rgba(196,181,253,0.14);color:#C4B5FD;display:flex;align-items:center;justify-content:center;flex:none}
.VD-enq-use .tick svg{width:12px;height:12px}
.VD-enq-use b{color:#fff;font-weight:600;letter-spacing:-.1px}

/* Form */
.VD-enq-form{background:rgba(255,255,255,0.04);border:1px solid rgba(196,181,253,0.16);border-radius:22px;padding:38px 36px;backdrop-filter:blur(8px)}
.VD-enq-grid{display:grid;grid-template-columns:1fr 1fr;gap:18px 16px}
.VD-enq-field{display:flex;flex-direction:column;gap:8px}
.VD-enq-field.full{grid-column:1 / -1}
.VD-enq-field label{font-size:13px;font-weight:600;color:rgba(196,181,253,0.7);letter-spacing:.3px;text-transform:uppercase;font-family:'Chakra Petch','Inter',sans-serif}
.VD-enq-field label .req{color:#C4B5FD;margin-left:3px}
.VD-enq-field input,.VD-enq-field select,.VD-enq-field textarea{appearance:none;background:rgba(255,255,255,0.06);border:1px solid rgba(255,255,255,0.14);border-radius:10px;padding:12px 14px;color:#fff;font-family:inherit;font-size:14.5px;line-height:1.5;transition:border-color .15s,background .15s}
.VD-enq-field input:focus,.VD-enq-field select:focus,.VD-enq-field textarea:focus{outline:0;border-color:#C4B5FD;background:rgba(255,255,255,0.10)}
.VD-enq-field input::placeholder,.VD-enq-field textarea::placeholder{color:rgba(255,255,255,0.75)}
.VD-enq-field select{background-image:url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='12'%20height='8'%20viewBox='0%200%2012%208'%3E%3Cpath%20d='M1%201l5%205%205-5'%20stroke='%23C4B5FD'%20stroke-width='1.8'%20fill='none'%20stroke-linecap='round'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 14px center;padding-right:38px}
.VD-enq-field textarea{min-height:96px;resize:vertical}

.VD-enq-phone{display:grid;grid-template-columns:96px 1fr;gap:8px}
.VD-enq-phone select{padding-right:30px;background-position:right 8px center}

.VD-enq-submit{margin-top:24px;display:flex;justify-content:space-between;align-items:center;gap:18px;flex-wrap:wrap}
.VD-enq-btn{appearance:none;border:0;cursor:pointer;display:inline-flex;align-items:center;gap:10px;padding:16px 32px;font-family:'Noto Sans HK','Inter',sans-serif;font-size:15px;font-weight:700;color:#0F2A47;background:linear-gradient(135deg,#C4B5FD 0%,#A855F7 100%);border-radius:999px;text-decoration:none;letter-spacing:.2px;box-shadow:0 8px 22px rgba(167,139,250,0.32);transition:all .15s}
.VD-enq-btn:hover{background:linear-gradient(135deg,#A855F7 0%,#9333EA 100%);transform:translateY(-1px);box-shadow:0 12px 28px rgba(167,139,250,0.45)}
.VD-enq-fine{font-size:13px;color:rgba(255,255,255,0.75);line-height:1.55;max-width:360px}

@media (max-width: 1024px){
  .VD-enq{padding:var(--section-pad-y-t) 0}
  .VD-enq-inner{grid-template-columns:1fr;gap:48px}
}
@media (max-width: 640px){
  .VD-enq{padding:var(--section-pad-y-m) 0}
  .VD-enq-form{padding:28px 22px}
  .VD-enq-grid{grid-template-columns:1fr}
}

/* ---------- FAQ ---------- */
.VD-faq{position:relative;background:linear-gradient(180deg,#F6F4FB 0%,#FAFAFE 100%);padding:var(--section-pad-y-d) 0;font-family:'Inter','Noto Sans HK','Noto Sans TC',sans-serif;color:#0F2A47}
.VD-faq-head{max-width:780px;margin-bottom:48px}
.VD-faq-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-faq-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-faq-lede{margin-top:18px;font-size:16px;line-height:1.7;color:#475569;max-width:560px}

.VD-faq-list{border-top:1px solid rgba(15,42,71,0.12)}
.VD-faq-item{border-bottom:1px solid rgba(15,42,71,0.12)}
.VD-faq-q{appearance:none;background:transparent;border:0;width:100%;padding:24px 0;display:grid;grid-template-columns:1fr 24px;align-items:center;gap:32px;text-align:left;cursor:pointer;font-family:inherit;color:inherit}
.VD-faq-q-text{font-size:18px;font-weight:600;color:#0F2A47;letter-spacing:-.2px;line-height:1.45;text-wrap:balance}
.VD-faq-toggle{width:24px;height:24px;color:#7C3AED;display:flex;align-items:center;justify-content:center;transition:transform .25s ease}
.VD-faq-item.open .VD-faq-toggle{transform:rotate(45deg)}
.VD-faq-toggle svg{width:18px;height:18px}
.VD-faq-a{display:grid;grid-template-rows:0fr;transition:grid-template-rows .3s ease}
.VD-faq-item.open .VD-faq-a{grid-template-rows:1fr}
.VD-faq-a > div{overflow:hidden;min-height:0}
.VD-faq-a p{margin:0 0 24px;font-size:15.5px;line-height:1.8;color:#475569;text-wrap:pretty;max-width:880px}
.VD-faq-a p strong{color:#0F2A47;font-weight:600}
.VD-faq-a p a{color:#7C3AED;text-decoration:none;border-bottom:1px solid currentColor;font-weight:600}
.VD-faq-a p a:hover{color:#0F2A47}

@media (max-width: 1024px){ .VD-faq{padding:var(--section-pad-y-t) 0} }
@media (max-width: 640px){
  .VD-faq{padding:var(--section-pad-y-m) 0}
  .VD-faq-q-text{font-size:16px}
  .VD-faq-a p{font-size:14.5px}
}

/* ---------- Final CTA ---------- */
.VD-fcta{background:radial-gradient(120% 120% at 80% 0%,#33215e 0%,#0F2A47 65%);color:#fff;padding:var(--section-pad-y-d) 0;position:relative;overflow:hidden;font-family:'Inter','Noto Sans HK','Noto Sans TC',sans-serif}
.VD-fcta::before{content:'';position:absolute;top:-200px;right:-200px;width:600px;height:600px;background:radial-gradient(circle,rgba(167,139,250,0.22) 0%,transparent 70%);pointer-events:none}
.VD-fcta-inner{position:relative;display:grid;grid-template-columns:1.3fr 1fr;gap:64px;align-items:end}
.VD-fcta-h2{margin:0;font-size:clamp(36px,4.4vw,60px);line-height:1.05;font-weight:700;letter-spacing:-1.8px;color:#fff;text-wrap:balance}
.VD-fcta-h2 .accent{background:linear-gradient(135deg,#C4B5FD 0%,#A855F7 100%);-webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent;color:transparent}
.VD-fcta-body{margin-top:22px;font-size:16.5px;line-height:1.75;color:rgba(255,255,255,0.78);max-width:540px;text-wrap:pretty}
.VD-fcta-tel{margin-top:18px;font-size:14px;color:rgba(255,255,255,0.6)}
.VD-fcta-tel a{color:#fff;text-decoration:none;border-bottom:1px dotted rgba(255,255,255,0.4);font-weight:600;margin-left:8px}
.VD-fcta-actions{display:flex;flex-direction:column;gap:12px;align-items:stretch}
.VD-fcta-btn{display:inline-flex;align-items:center;justify-content:center;gap:10px;padding:18px 28px;font-size:15.5px;font-weight:600;letter-spacing:.3px;border-radius:999px;text-decoration:none;transition:all .15s;white-space:nowrap;border:1.5px solid transparent}
.VD-fcta-btn.primary{color:#0F2A47;background:#C4B5FD;border-color:#C4B5FD}
.VD-fcta-btn.primary:hover{background:#fff;border-color:#fff;transform:translateY(-1px)}
.VD-fcta-btn.outline{color:#fff;background:transparent;border-color:rgba(255,255,255,0.40)}
.VD-fcta-btn.outline:hover{border-color:#fff;background:rgba(255,255,255,0.06)}

@media (max-width: 900px){ .VD-fcta-inner{grid-template-columns:1fr;gap:36px;align-items:start} }
`;

// ---- Enquiry Form ----
const VdIcTick = () => (<svg viewBox="0 0 12 12" fill="none" aria-hidden="true"><path d="M2.5 6.5l2.5 2.5 5-5" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" /></svg>);

function VideoEnquiry() {
  return (
    <>
      <style>{VD_END_CSS}</style>
      <section className="VD-enq" id="enquiry" data-screen-label="07 Enquiry">
        <div className="container VD-enq-inner">
          <div>
            <h2 className="VD-enq-h2">與我們的 <span className="accent">影片 CDN 專家</span>對談</h2>
            <p className="VD-enq-lede">
              若你計劃大型直播事件、運營 OTT 平台、需要客製化整合，或同時部署多區域節點，請填寫表格，香港團隊會盡快跟進。
            </p>
          </div>

          <CdnEnquiryForm prefix="vd" />
        </div>
      </section>
    </>
  );
}

// ---- FAQ ----
const VD_FAQS = [
  {
    q: '影片 CDN 與一般 CDN 有何分別？',
    a: '一般 CDN 主要快取靜態網頁資源（圖片、JS、CSS）；影片 CDN 在此基礎上針對直播訊號與大型影片檔案優化，包括低延時 chunk 處理、多協定（HLS / MPEG-DASH / MSS / HDS）原生支援、自適應位元率、簽名連結與防盜鏈、即時觀看分析等。如業務涉及直播或大量影片點播，建議使用影片 CDN。',
  },
  {
    q: 'UD 影片 CDN 支援哪些直播協定與影片格式？',
    a: '直播協定支援 HLS、MPEG-DASH、MSS、HDS；點播檔案支援 MP4、M3U8、MOV、WebM、AVI、FLV。HLS 與 MPEG-DASH 兩大協定合共佔現代串流市場約 85%，UD 影片 CDN 兩者全面支援。',
  },
  {
    q: '如何同時服務本港、中國與全球觀眾？',
    a: '可在同一帳戶內同時啟用本港、中國、全球三套區域 plan，按觀眾來源自動分配到對應節點；亦可選用智能 CDN 自動將不同地區流量導向最佳線路。',
  },
  {
    q: '服務中國內地觀眾需要 ICP 備案嗎？',
    a: '不需要。UD 影片 CDN 採用中國電信 CN2 GIA 專線連接中國周邊節點，毋須申請 ICP 備案即可服務內地觀眾。',
  },
  {
    q: '大型直播事件 / 高並發如何處理？',
    a: '直播當日流量會自動分散至各邊緣節點，源站只需處理 origin pull。如預期大型賽事或品牌發佈會的並發人數極高，建議提前透過上方表格通知銷售團隊，預留專屬節點與頻寬。',
  },
  {
    q: '如何防止盜鏈、限制觀看區域？',
    a: '支援簽名連結（Token URL，按時效與 IP 簽發）、防盜鏈（按 referer 攔截）、地區限制（Geo-block 按國家或地區准入或禁止）。可在控制台或開發者介面配置。',
  },
  {
    q: '點開始用？',
    a: '登入 UD CDN 控制台輸入影片網域、驗證擁有權，設定快取規則並指向 UD CDN 即可生效。整個流程毋須變更現有推流伺服器或點播儲存架構，可於同一個工作天內完成。',
  },
  {
    q: '包含哪些安全防護？',
    a: '所有影片 CDN 流量自動隱藏源站真實位址，並內建免費 Let\'s Encrypt SSL 證書、網頁應用程式防火牆與 DDoS 防護，毋須額外加購安全模組。',
  },
  {
    q: '適合 OTT 平台 / 線上教育 / 電商直播帶貨嗎？',
    a: '適合。UD 影片 CDN 同時支援高並發直播（電商帶貨、賽事直播）、長時段點播（OTT / 線上教育）、以及短影片即時推送（社交平台）等多種業務模式。',
  },
  {
    q: '影片 CDN 與動態內容 CDN、智能 CDN 如何配合？',
    a: '影片 CDN 主要負責影片資源（直播 + 點播）；動態內容 CDN 處理 API / WebSocket 即時數據（例如直播聊天室、即時投票）；智能 CDN 負責跨區域流量分配。三者可同時啟用，完整覆蓋影片業務。',
  },
];

function VideoFAQ() {
  const [open, setOpen] = useVDEndState(0);
  return (
    <section className="VD-faq" id="faq" data-screen-label="08 FAQ">
      <div className="container">
        <div className="VD-faq-head">
          <h2 className="VD-faq-h2">常見<span className="accent">問題</span></h2>
          <p className="VD-faq-lede">如以上未能解答你的疑問，歡迎直接透過上方表格聯絡我們的香港工程團隊。</p>
        </div>
        <div className="VD-faq-list">
          {VD_FAQS.map((f, i) => (
            <div className={`VD-faq-item ${open === i ? 'open' : ''}`} key={i}>
              <button className="VD-faq-q" onClick={() => setOpen(open === i ? -1 : i)} aria-expanded={open === i}>
                <span className="VD-faq-q-text">{f.q}</span>
                <span className="VD-faq-toggle" aria-hidden="true">
                  <svg viewBox="0 0 18 18" fill="none">
                    <line x1="9" y1="2" x2="9" y2="16" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" />
                    <line x1="2" y1="9" x2="16" y2="9" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" />
                  </svg>
                </span>
              </button>
              <div className="VD-faq-a"><div><p>{f.a}</p></div></div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ---- Final CTA ----
function VideoFinalCTA() {
  return (
    <section className="VD-fcta" data-screen-label="09 Final CTA">
      <div className="container VD-fcta-inner">
        <div>
          <h2 className="VD-fcta-h2">立即啟用影片加速，<br /><span className="accent">直播零卡頓、點播秒開</span></h2>
          <p className="VD-fcta-body">免費試用、按用量收費、無需長期合約。由香港團隊為你規劃最合適的影片 CDN 配置。</p>
          <p className="VD-fcta-tel">服務查詢熱線：<a href="tel:+85225547545" data-cta="open-call-sales">(+852) 2554 7545</a></p>
        </div>
        <div className="VD-fcta-actions">
          <a className="VD-fcta-btn primary" href="https://passport.8338.hk/zh-hant/signup" data-cta="start-trial">免費試用 →</a>
          <a className="VD-fcta-btn outline" href="#enquiry" data-cta="contact-sales">與影片 CDN 專家對談</a>
        </div>
      </div>
    </section>
  );
}

window.VideoEnquiry = VideoEnquiry;
window.VideoFAQ = VideoFAQ;
window.VideoFinalCTA = VideoFinalCTA;
