// page-terms.jsx — /terms (bilingual EN + VN)

const Terms = ({ lang }) => {
  const vn = lang === 'vi';
  const L = (en, v) => (vn ? v : en);
  const legal = window.SN_LEGAL || {};
  const email = window.SN_SUPPORT_EMAIL;
  const TOC = [
    ['who', L('Who you buy from', 'Bạn mua từ ai')],
    ['licence', L('Your licence', 'Giấy phép của bạn')],
    ['trial', L('Trial & free mode', 'Dùng thử & chế độ miễn phí')],
    ['price', L('Price & payment', 'Giá & thanh toán')],
    ['refunds', L('Refunds', 'Hoàn tiền')],
    ['updates', L('Updates', 'Cập nhật')],
    ['requirements', L('Requirements', 'Yêu cầu hệ thống')],
    ['allowed', L('What you may not do', 'Điều không được làm')],
    ['warranty', L('Warranty & liability', 'Bảo đảm & trách nhiệm')],
    ['law', L('Governing law', 'Luật áp dụng')],
    ['changes', L('Changes', 'Thay đổi điều khoản')],
  ];
  const [activeSec, setActiveSec] = React.useState('who');
  React.useEffect(() => {
    const onScroll = () => {
      let cur = TOC[0][0];
      for (const [id] of TOC) {
        const el = document.getElementById(id);
        if (el && el.getBoundingClientRect().top <= 140) cur = id;
      }
      setActiveSec((p) => (p === cur ? p : cur));
    };
    window.addEventListener('scroll', onScroll, { passive: true });
    onScroll();
    return () => window.removeEventListener('scroll', onScroll);
  }, [lang]);
  const goSec = (e, id) => {
    e.preventDefault();
    const el = document.getElementById(id);
    if (!el) return;
    window.scrollTo({ top: el.getBoundingClientRect().top + window.pageYOffset - 92, behavior: 'smooth' });
  };
  const E = (en, v) => <p>{vn ? v : en}</p>;
  const Bi = (en, v) => <>{vn ? v : en}</>;
  const days = legal.refundWindow;
  const refundCond = (legal.refundConditions || {})[vn ? 'vi' : 'en'];

  return (
    <main>
      <section className="ph">
        <div className="container">
          <div className="ph-inner">
            <Eyebrow>{L('Terms', 'Điều khoản')}</Eyebrow>
            <h1 style={{ marginTop: 14 }}>{L('Terms of sale and use.', 'Điều khoản bán hàng và sử dụng.')}</h1>
            <p>{L(
              'Snapovo is a one-time purchase for macOS. No subscription, no account, no data collection. These terms cover what you buy, what you may do with it, and what happens if something goes wrong.',
              'Snapovo là phần mềm macOS mua một lần. Không thuê bao, không tài khoản, không thu thập dữ liệu. Điều khoản này nói rõ bạn mua gì, được dùng thế nào, và xử lý ra sao khi có vấn đề.'
            )}</p>
            <p style={{ fontFamily: 'var(--font-mono)', fontSize: 12, color: 'var(--text-dim)', marginTop: 14 }}>{L('Last updated', 'Cập nhật lần cuối')} · {L('Sep 1, 2026', '01/09/2026')}</p>
          </div>
        </div>
      </section>

      <div className="container privacy-page">
        <aside className="privacy-toc">
          <div style={{ fontSize: 11, color: 'var(--text-dim)', textTransform: 'uppercase', letterSpacing: '0.06em', fontWeight: 500, marginBottom: 8 }}>{L('On this page', 'Trong trang này')}</div>
          {TOC.map(([id, lbl]) => (
            <a key={id} href={`#${id}`} className={id === activeSec ? 'is-active' : ''} onClick={(e) => goSec(e, id)}>{lbl}</a>
          ))}
        </aside>

        <article className="prose">
          <h2 id="who">{L('Who you are buying from', 'Bạn mua từ ai')}</h2>
          {E(
            'A Snapovo purchase has two layers, and it helps to know which is which. You buy from Lemon Squeezy: they are the merchant of record for the order, and they own the transaction, the payment, the invoice, any applicable VAT or sales tax, refunds and chargebacks. Card details never reach us.',
            'Mỗi lần mua Snapovo có hai lớp, và bạn nên biết lớp nào là gì. Bạn mua từ Lemon Squeezy: họ là đơn vị đứng tên bán hàng (merchant of record) cho đơn hàng, và họ phụ trách giao dịch, thanh toán, hóa đơn, VAT hoặc thuế bán hàng áp dụng, hoàn tiền và chargeback. Thông tin thẻ không bao giờ đi qua chúng tôi.'
          )}
          <p>{Bi(
            <>Money questions — payment, invoice, tax, refund — go to Lemon Squeezy. Software questions come to us, by email, at <a href={`mailto:${email}`}>{email}</a>, which is our single point of contact. The licence to use the software is what this page sets out.</>,
            <span>Chuyện tiền — thanh toán, hóa đơn, thuế, hoàn tiền — thuộc Lemon Squeezy. Chuyện phần mềm thuộc chúng tôi, qua email <a href={`mailto:${email}`}>{email}</a>, đầu mối liên hệ duy nhất. Giấy phép sử dụng phần mềm chính là nội dung trang này.</span>
          )}</p>

          <h2 id="licence">{L('What your licence gives you', 'Giấy phép của bạn gồm gì')}</h2>
          {E(
            'You are buying a perpetual, non-exclusive licence to use Snapovo for personal or commercial work. You are not buying the software itself; copyright stays with the publisher.',
            'Bạn mua giấy phép sử dụng Snapovo vĩnh viễn, không độc quyền, cho mục đích cá nhân hoặc công việc. Bạn không mua bản thân phần mềm; bản quyền vẫn thuộc nhà phát hành.'
          )}
          {E(
            'A licence is bound to the Mac it is activated on. The two plans differ only in how many Macs may be activated at the same time: one Mac, or two Macs. Nothing else about the app changes between them.',
            'Giấy phép ràng theo máy đã kích hoạt. Hai gói chỉ khác nhau ở số máy Mac được kích hoạt cùng lúc: 1 máy hoặc 2 máy. Ngoài ra không có gì khác biệt về tính năng.'
          )}
          {E(
            'Changing Macs is up to you and needs no request: open Settings → License, release the old Mac, then activate the new one. You may do this as often as you need.',
            'Đổi máy do bạn tự làm, không cần yêu cầu hỗ trợ: mở Cài đặt → License, giải phóng máy cũ, rồi kích hoạt máy mới. Bạn có thể làm việc này bao nhiêu lần cũng được.'
          )}

          <h2 id="trial">{L('Trial, and what happens after it', 'Dùng thử, và sau khi hết hạn')}</h2>
          {E(
            'Snapovo is free to try for 7 days, with up to 3 presets. No card and no account is required to start.',
            'Snapovo dùng thử miễn phí 7 ngày, tối đa 3 preset. Không cần thẻ, không cần tài khoản để bắt đầu.'
          )}
          {E(
            'When the trial ends the app does not lock your data and nothing is deleted. Presets and chains you already made keep working, forever, at no cost. What you lose is the ability to create or edit workspaces, chains, automations and appearance settings until you buy a licence.',
            'Khi hết hạn dùng thử, app không khoá dữ liệu và không xoá bất cứ thứ gì. Preset và chuỗi bạn đã tạo vẫn chạy vĩnh viễn, miễn phí. Bạn chỉ mất khả năng tạo hoặc sửa workspace, chuỗi, tự động hoá và giao diện cho tới khi mua giấy phép.'
          )}

          <h2 id="price">{L('Price and payment', 'Giá và thanh toán')}</h2>
          <ul>
            <li>{Bi(<><strong>1 Mac — 9.99 USD</strong>, one-time.</>, <span><strong>1 máy Mac — 9,99 USD</strong>, trả một lần.</span>)}</li>
            <li>{Bi(<><strong>2 Macs — 16.99 USD</strong>, one-time.</>, <span><strong>2 máy Mac — 16,99 USD</strong>, trả một lần.</span>)}</li>
          </ul>
          {E(
            'There is no subscription and no recurring charge of any kind. Prices are in US dollars and exclude any tax Lemon Squeezy is required to add for your country.',
            'Không có thuê bao và không có khoản thu định kỳ nào. Giá tính bằng đô-la Mỹ, chưa gồm thuế mà Lemon Squeezy phải cộng thêm theo quốc gia của bạn.'
          )}

          <h2 id="refunds">{L('Refunds', 'Hoàn tiền')}</h2>
          <p>{Bi(
            <><strong>{days}-day refund window.</strong> {refundCond}</>,
            <span><strong>Hoàn tiền trong {days} ngày.</strong> {refundCond}</span>
          )}</p>
          <p>{Bi(
            <><strong>How to request one:</strong> email <a href={`mailto:${email}?subject=${encodeURIComponent('Snapovo refund request')}`}>{email}</a> and include <strong>either</strong> the email address you used at checkout <strong>or</strong> your licence key. Either one is enough to find the order — we ask for both options because the address you paid with is often not the address you use day to day, while your licence key is always right there in the app under Settings → License.</>,
            <span><strong>Cách yêu cầu:</strong> gửi email tới <a href={`mailto:${email}?subject=${encodeURIComponent('Snapovo — yêu cầu hoàn tiền')}`}>{email}</a>, kèm <strong>hoặc</strong> địa chỉ email bạn đã dùng khi mua, <strong>hoặc</strong> license key của bạn. Một trong hai là đủ để tìm đơn hàng — chúng tôi nêu cả hai vì email lúc mua thường không phải email bạn dùng hằng ngày, còn license key thì luôn có sẵn trong app tại Cài đặt → License.</span>
          )}</p>
          {E(
            'Once a refund is approved, Lemon Squeezy returns the money to the original payment method. Expect it to take up to 10 days to appear on your bank or card statement — that delay is the bank’s, not a sign that something went wrong. Please email us rather than disputing the charge with your bank: a direct email is faster for you, and a dispute filed while a refund is already on its way only slows both of them down.',
            'Sau khi yêu cầu được chấp thuận, Lemon Squeezy hoàn tiền về phương thức thanh toán ban đầu. Hãy chờ tới 10 ngày để khoản tiền hiện trên sao kê ngân hàng hoặc thẻ — độ trễ đó thuộc phía ngân hàng, không phải dấu hiệu có vấn đề. Hãy email cho chúng tôi thay vì khiếu nại giao dịch với ngân hàng: email trực tiếp nhanh hơn cho bạn, và một khiếu nại mở ra trong lúc tiền đã đang trên đường về chỉ làm chậm cả hai.'
          )}
          {E(
            'Your licence key is deactivated when the refund is processed.',
            'License key của bạn sẽ bị vô hiệu khi việc hoàn tiền được xử lý.'
          )}

          <h2 id="updates">{L('Updates', 'Cập nhật')}</h2>
          {E(
            'Updates are included in your purchase. There is no upgrade fee and no maintenance plan. Snapovo checks for updates automatically after installation; the check is anonymous and you can turn it off in Settings.',
            'Cập nhật đã bao gồm trong lần mua. Không có phí nâng cấp, không có gói bảo trì. Snapovo tự kiểm tra cập nhật sau khi cài; lần kiểm tra này ẩn danh và bạn có thể tắt trong Cài đặt.'
          )}
          {E(
            'We do not promise a delivery date for any specific feature. Anything described as planned may change or be dropped.',
            'Chúng tôi không cam kết ngày ra mắt cho bất kỳ tính năng cụ thể nào. Những gì được mô tả là dự kiến đều có thể thay đổi hoặc bị bỏ.'
          )}

          <h2 id="requirements">{L('System requirements', 'Yêu cầu hệ thống')}</h2>
          {E(
            'Snapovo requires macOS 13.5 or later. Check this before buying: a Mac that does not meet the requirement is not a defect in the software.',
            'Snapovo yêu cầu macOS 13.5 trở lên. Hãy kiểm tra trước khi mua: máy Mac không đạt yêu cầu này không phải là lỗi của phần mềm.'
          )}

          <h2 id="allowed">{L('What you may not do', 'Điều bạn không được làm')}</h2>
          <ul>
            <li>{Bi('Share, resell, sublicense or publish your licence key.', 'Chia sẻ, bán lại, cấp phép lại hoặc công bố license key của bạn.')}</li>
            <li>{Bi('Circumvent the licence check, the trial limits, or the activation limit.', 'Vượt qua cơ chế kiểm tra giấy phép, giới hạn dùng thử hoặc giới hạn kích hoạt.')}</li>
            <li>{Bi('Reverse-engineer, decompile or repackage the app, except where the law expressly allows it.', 'Dịch ngược, giải biên dịch hoặc đóng gói lại app, trừ khi pháp luật cho phép rõ ràng.')}</li>
          </ul>
          {E(
            'A licence found to be shared publicly may be deactivated without refund.',
            'Giấy phép bị phát hiện chia sẻ công khai có thể bị vô hiệu mà không hoàn tiền.'
          )}

          <h2 id="warranty">{L('Warranty and liability', 'Bảo đảm và trách nhiệm')}</h2>
          {E(
            'Snapovo is provided as is. We work hard to make it reliable, but we cannot warrant that it will be free of defects or that it will restore every window of every app on every Mac, since it depends on macOS behaviour and on the apps you use.',
            'Snapovo được cung cấp theo hiện trạng. Chúng tôi cố gắng để nó chạy ổn định, nhưng không thể bảo đảm hoàn toàn không có lỗi, hoặc bảo đảm khôi phục được mọi cửa sổ của mọi app trên mọi máy Mac — điều này phụ thuộc vào hành vi của macOS và các app bạn dùng.'
          )}
          {E(
            'To the extent the law permits, our total liability for any claim relating to Snapovo is limited to the amount you paid for your licence. Nothing here limits rights that your local consumer law gives you and does not allow to be waived.',
            'Trong phạm vi pháp luật cho phép, tổng trách nhiệm của chúng tôi cho mọi khiếu nại liên quan tới Snapovo được giới hạn ở số tiền bạn đã trả cho giấy phép. Điều khoản này không giới hạn các quyền mà luật bảo vệ người tiêu dùng tại nơi bạn ở trao cho bạn và không cho phép từ bỏ.'
          )}

          <h2 id="law">{L('Governing law', 'Luật áp dụng')}</h2>
          {E(
            `These terms are governed by and construed in accordance with the laws of ${legal.governingLaw}, without regard to conflict of law principles, and any dispute is resolved before the competent courts of ${legal.jurisdiction}.`,
            `Điều khoản này được điều chỉnh và giải thích theo pháp luật Việt Nam, không áp dụng các nguyên tắc xung đột pháp luật, và mọi tranh chấp được giải quyết tại toà án có thẩm quyền tại Việt Nam.`
          )}
          {E(
            'Payment, tax and refund matters are separately subject to the Lemon Squeezy buyer terms you accepted at checkout.',
            'Riêng các vấn đề thanh toán, thuế và hoàn tiền chịu điều chỉnh bởi điều khoản người mua của Lemon Squeezy mà bạn đã đồng ý khi thanh toán.'
          )}
          {E(
            'Before starting any formal process, please email us — nearly everything is solved that way.',
            'Trước khi tiến hành thủ tục chính thức, hãy gửi email cho chúng tôi — gần như mọi việc đều giải quyết được theo cách đó.'
          )}

          <h2 id="changes">{L('Changes to these terms', 'Thay đổi điều khoản')}</h2>
          {E(
            'We may update these terms for future releases. A licence you already bought is governed by the terms in force on the day you bought it. The date at the top of this page always shows the current version.',
            'Chúng tôi có thể cập nhật điều khoản cho các bản phát hành sau. Giấy phép bạn đã mua chịu điều chỉnh bởi điều khoản có hiệu lực vào ngày bạn mua. Ngày ở đầu trang luôn cho biết phiên bản hiện hành.'
          )}

          <p style={{ marginTop: 40, paddingTop: 20, borderTop: '1px solid var(--border)', color: 'var(--text-dim)', fontSize: 13 }}>
            {Bi('© 2026 Snapovo. Questions about these terms? ', '© 2026 Snapovo. Câu hỏi về điều khoản? ')}
            <a style={{ color: 'var(--accent)' }} href={`mailto:${email}`}>{email}</a>
          </p>
        </article>
      </div>
    </main>
  );
};

window.Terms = Terms;
