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

const Privacy = ({ lang }) => {
  const showVN = lang === 'vi';
  const TOC_IDS = ['summary', 'data', 'storage', 'network', 'updates', 'feedback'];
  const [activeSec, setActiveSec] = React.useState('summary');
  React.useEffect(() => {
    const onScroll = () => {
      let cur = TOC_IDS[0];
      for (const id of TOC_IDS) {
        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);
  }, []);
  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, vn) => <p>{showVN ? vn : en}</p>;
  const Bi = (en, vn) => <>{showVN ? vn : en}</>;

  return (
    <main>
      <section className="ph">
        <div className="container">
          <div className="ph-inner">
            <Eyebrow>{showVN ? 'Quyền riêng tư' : 'Privacy'}</Eyebrow>
            <h1 style={{ marginTop: 14 }}>{showVN ? 'Dữ liệu của bạn ở lại trên máy bạn.' : 'Your data stays on your Mac.'}</h1>
            <p>{showVN
              ? 'Snapovo không thu thập telemetry, không có tài khoản, hoạt động cục bộ.'
              : 'Snapovo collects no telemetry, has no accounts, and is local-first.'}</p>
            <p style={{ fontFamily: 'var(--font-mono)', fontSize: 12, color: 'var(--text-dim)', marginTop: 14 }}>{showVN ? 'Cập nhật lần cuối' : 'Last updated'} · {showVN ? '01/09/2026' : 'Sep 1, 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 }}>{showVN ? 'Trong trang này' : 'On this page'}</div>
          {[
            ['summary', showVN ? 'Tóm tắt' : 'Summary'],
            ['data', showVN ? 'Dữ liệu xử lý' : 'Data processed'],
            ['storage', showVN ? 'Lưu trữ' : 'Storage'],
            ['network', showVN ? 'Kết nối mạng' : 'Network'],
            ['updates', showVN ? 'Cập nhật' : 'Updates'],
            ['feedback', showVN ? 'Phản hồi' : 'Feedback'],
          ].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="summary">{showVN ? 'Tóm tắt' : 'Summary'}</h2>
          {E(
            'Snapovo has no Snapovo account and is local-first. Pro licenses are sold through Lemon Squeezy and activated with an email + license key. Your presets, chains, settings and Insights stats stay on your Mac — we have no way to see them.',
            'Snapovo không có tài khoản và hoạt động cục bộ. Giấy phép Pro bán qua Lemon Squeezy, kích hoạt bằng email + license key. Preset, chuỗi, cài đặt và thống kê Insights nằm trên máy bạn — chúng tôi không có cách nào xem được.'
          )}

          <h2 id="data">{showVN ? 'Dữ liệu Snapovo xử lý' : 'Data Snapovo processes'}</h2>
          <p>{Bi(
            'Snapovo does not read window contents, screenshot the screen, log keystrokes, or capture clipboard contents.',
            'Snapovo không đọc nội dung cửa sổ, không chụp màn hình, không ghi phím, không sao chép clipboard.'
          )}</p>

          <h2 id="storage">{showVN ? 'Lưu trữ ở đâu' : 'Where it lives'}</h2>
          {E(
            'Presets, chains and settings are stored in local files under ~/Library/Application Support/Snapovo/ plus macOS UserDefaults. Your license and trial state are kept in the macOS Keychain (signed), not in a plain file. Nothing here is uploaded — it stays under the protection of your macOS user account.',
            'Preset, chuỗi và cài đặt được lưu trong các tệp cục bộ tại ~/Library/Application Support/Snapovo/ cùng với macOS UserDefaults. Giấy phép và trạng thái dùng thử được giữ trong macOS Keychain (có ký), không phải tệp thường. Không có gì ở đây được tải lên — tất cả nằm dưới bảo vệ tài khoản macOS của bạn.'
          )}

          <h2 id="network">{showVN ? 'Kết nối mạng Snapovo thực hiện' : 'Network connections Snapovo makes'}</h2>
          <p>{Bi('There are exactly three:', 'Chỉ có đúng ba:')}</p>
          <ul>
            <li>{Bi(
              <><strong>Update check</strong> — automatic checks are <strong>on</strong> after installation, so Snapovo asks the update server for a new version from time to time; it also happens when you click Check for Updates…. The request is anonymous and carries no personal identifiers. You can switch it off in Settings → “Automatically check for updates”, which leaves only manual checks.</>,
              <span><strong>Kiểm tra cập nhật</strong> — tự kiểm tra cập nhật <strong>bật sẵn</strong> sau khi cài, nên Snapovo định kỳ hỏi máy chủ cập nhật xem có bản mới; việc này cũng xảy ra khi bạn bấm Check for Updates…. Lần hỏi này ẩn danh, không kèm định danh cá nhân. Bạn có thể tắt trong Cài đặt → “Automatically check for updates”, khi đó chỉ còn kiểm tra thủ công.</span>
            )}</li>
            <li>{Bi(
              <><strong>License activation &amp; validation</strong> — to Lemon Squeezy, only when activating or validating a license. Sends the license key plus a device name (host name + a short device identifier) to enforce the per-license Mac limit.</>,
              <span><strong>Kích hoạt & xác thực giấy phép</strong> — tới Lemon Squeezy, chỉ khi kích hoạt hoặc xác thực. Gửi license key cùng tên thiết bị (hostname + mã máy rút gọn) để giới hạn số máy theo giấy phép.</span>
            )}</li>
            <li>{Bi(
              <><strong>Send Feedback</strong> — only when you press the button in Help → Send Feedback…, only with the data you explicitly chose to attach.</>,
              <span><strong>Send Feedback</strong> — chỉ khi bạn bấm nút trong Help → Send Feedback…, chỉ với dữ liệu bạn đã chọn đính kèm.</span>
            )}</li>
          </ul>

          <h2 id="updates">{showVN ? 'Tự cập nhật' : 'Auto-updates'}</h2>
          {E(
            'Snapovo uses Sparkle 2 for updates, and automatic checks are enabled when you install it — for every user, including the free and trial versions. Snapovo therefore contacts the update server periodically to ask whether a newer version exists. That request is anonymous: it carries no account, no licence key and no personal identifiers. If you would rather it never happened, turn off “Automatically check for updates” in Settings; Snapovo then only checks when you ask it to.',
            'Snapovo dùng Sparkle 2 để cập nhật, và tự kiểm tra cập nhật được bật sẵn khi bạn cài — với mọi người dùng, kể cả bản miễn phí và bản dùng thử. Vì vậy Snapovo định kỳ liên hệ máy chủ cập nhật để hỏi xem có bản mới hay không. Lần hỏi đó ẩn danh: không kèm tài khoản, không kèm license key, không kèm định danh cá nhân. Nếu bạn không muốn điều này xảy ra, hãy tắt “Automatically check for updates” trong Cài đặt; khi đó Snapovo chỉ kiểm tra khi bạn yêu cầu.'
          )}

          <h2 id="feedback">{showVN ? 'Phản hồi & chẩn đoán' : 'Feedback & diagnostics'}</h2>
          {E(
            'Send Feedback shows you the exact payload before it leaves the machine: your message, plus whatever you ticked (macOS version, recent diagnostic logs with file paths sanitised). You can copy the payload to the clipboard and email it manually if you prefer not to use the in-app sender.',
            'Send Feedback hiển thị payload chính xác trước khi rời máy: tin nhắn của bạn, cộng với những gì bạn đã chọn (phiên bản macOS, log chẩn đoán gần đây với đường dẫn được làm sạch). Bạn có thể copy payload và gửi email thủ công nếu không muốn dùng trình gửi trong app.'
          )}

          <p style={{ marginTop: 40, paddingTop: 20, borderTop: '1px solid var(--border)', color: 'var(--text-dim)', fontSize: 13 }}>
            {Bi(
              <>Questions? <a style={{ color: 'var(--accent)' }} href="mailto:snapovo.support.app@gmail.com">snapovo.support.app@gmail.com</a></>,
              <span>Câu hỏi? <a style={{ color: 'var(--accent)' }} href="mailto:snapovo.support.app@gmail.com">snapovo.support.app@gmail.com</a></span>
            )}
          </p>
        </article>
      </div>
    </main>
  );
};

window.Privacy = Privacy;
