<?php
declare(strict_types=1);
define('BASE_PATH', __DIR__ . '/..');
require_once BASE_PATH . '/src/bootstrap.php';

use PostbackServer\Translation;

$lang = Translation::getLanguage();
?>
<!DOCTYPE html>
<html lang="<?= htmlspecialchars($lang) ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= Translation::get('footer_privacy') ?> – PostbackFlow</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<style>
:root {
  --bg:#040812;--surface:#0d1424;--surface2:#131d30;--border:#1a2640;
  --primary:#6366f1;--pl:#818cf8;--accent:#22d3ee;--text:#f1f5f9;--muted:#64748b;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  padding: 100px 20px 60px;
}
.glow {
  position: absolute;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 600px;
  background: radial-gradient(ellipse, rgba(99, 102, 241, 0.12) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}
nav {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 100;
  background: rgba(4, 8, 18, 0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}
.nav-logo {
  font-size: 1.25rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--pl), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-decoration: none;
}
.nav-back {
  color: var(--pl);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
}
.container {
  max-width: 800px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
h1 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--text), var(--pl));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 30px;
}
h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: 30px;
  margin-bottom: 12px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}
p {
  margin-bottom: 16px;
  color: #cbd5e1;
  font-size: 0.95rem;
}
ul {
  margin-bottom: 16px;
  padding-left: 20px;
  color: #cbd5e1;
  font-size: 0.95rem;
}
li {
  margin-bottom: 6px;
}
footer {
  text-align: center;
  margin-top: 60px;
  font-size: 0.8rem;
  color: var(--muted);
}
</style>
</head>
<body>
<div class="glow"></div>
<nav>
  <a href="/" class="nav-logo">⚡ PostbackFlow</a>
  <a href="/" class="nav-back">← <?= $lang === 'vi' ? 'Quay lại Trang chủ' : 'Back to Home' ?></a>
</nav>

<div class="container">
  <div class="card">
    <?php if ($lang === 'vi'): ?>
      <h1>Chính Sách Bảo Mật</h1>
      <div class="meta">Cập nhật lần cuối: <?= date('d/m/Y') ?></div>

      <p>Chào mừng bạn đến với PostbackFlow. Chúng tôi cam kết bảo vệ quyền riêng tư và dữ liệu cá nhân của bạn theo tiêu chuẩn cao nhất. Chính sách bảo mật này giải thích cách chúng tôi xử lý thông tin khi bạn sử dụng dịch vụ của chúng tôi.</p>

      <h2>1. Thông tin Chúng tôi Thu thập</h2>
      <p>Khi bạn sử dụng phần mềm tracking, hệ thống sẽ tự động xử lý các thông số kỹ thuật để đo lường chuyển đổi quảng cáo:</p>
      <ul>
        <li><strong>Dữ liệu kỹ thuật:</strong> Địa chỉ IP, chuỗi User-Agent trình duyệt, quốc gia (được phân giải ở cấp Cloudflare), loại thiết bị, hệ điều hành và Referrer URL.</li>
        <li><strong>Mã định danh click:</strong> Google Click ID (gclid/wbraid/gbraid), Meta Click ID (fbclid), TikTok Click ID (ttclid) và các UTM parameters liên quan.</li>
        <li><strong>Thông tin tài khoản:</strong> Địa chỉ email và tên bạn cung cấp khi tạo tài khoản để quản lý thanh toán và thông báo.</li>
      </ul>

      <h2>2. Cách Chúng tôi Sử dụng Dữ liệu</h2>
      <p>Chúng tôi chỉ sử dụng dữ liệu để vận hành tính năng cốt lõi của tracker:</p>
      <ul>
        <li>Nhận dạng và phân loại lưu lượng truy cập (chặn bot, kiểm soát reviewer của ad networks).</li>
        <li>Khớp chuyển đổi (conversion) từ affiliate network gửi về với click gốc của người dùng.</li>
        <li>Đẩy dữ liệu chuyển đổi về tài khoản quảng cáo của bạn qua API (Meta CAPI, Google Ads REST API...).</li>
      </ul>

      <h2>3. Bảo mật Dữ liệu & Mã hóa băm (Hashing)</h2>
      <p>Chúng tôi luôn ưu tiên bảo mật dữ liệu ở mức tối đa:</p>
      <ul>
        <li><strong>Mã hóa băm một chiều (Hashing):</strong> Mọi thông tin cá nhân của khách hàng cuối (như Email, Số điện thoại) đi kèm postback luôn được băm bằng thuật toán SHA256 trước khi lưu trữ hoặc truyền đi sang Google/Meta API. Điều này đảm bảo dữ liệu không thể bị khôi phục hoặc đọc trộm.</li>
        <li><strong>Mã hóa tại chỗ:</strong> Các thông tin cấu hình nhạy cảm (như Token tài khoản quảng cáo, API Keys) được mã hóa bằng chuẩn AES-256 trước khi lưu vào database.</li>
      </ul>

      <h2>4. Lưu trữ & Xóa dữ liệu</h2>
      <p>Dữ liệu click thô và cache IP bot được tự động dọn dẹp định kỳ sau 7 đến 30 ngày để tối ưu hệ thống và bảo đảm tính riêng tư. Bạn có thể yêu cầu xóa toàn bộ tài khoản và các dữ liệu liên quan bất kỳ lúc nào bằng cách liên hệ với bộ phận hỗ trợ.</p>

      <h2>5. Bản quyền và Liên hệ</h2>
      <p>Mọi thắc mắc về Chính sách bảo mật vui lòng gửi về hòm thư support@postbackflow.com.</p>
    <?php else: ?>
      <h1>Privacy Policy</h1>
      <div class="meta">Last Updated: <?= date('F j, Y') ?></div>

      <p>Welcome to PostbackFlow. We are committed to protecting your privacy and personal data. This Privacy Policy explains how we collect, process, and protect your information when you use our conversion tracking software.</p>

      <h2>1. Information We Collect</h2>
      <p>To operate our tracking and routing engine, we process technical transaction parameters:</p>
      <ul>
        <li><strong>Technical Traffic Data:</strong> IP Address, browser User-Agent string, country code (resolved via Cloudflare headers), device type, operating system, and referrer URL.</li>
        <li><strong>Ad Click Identifiers:</strong> Google Click ID (gclid/wbraid/gbraid), Meta Click ID (fbclid), TikTok Click ID (ttclid), and standard UTM parameters.</li>
        <li><strong>Account Information:</strong> Your name and email address provided during signup for billing and system alert purposes.</li>
      </ul>

      <h2>2. How We Use Data</h2>
      <p>We process data strictly to deliver our core tracking services:</p>
      <ul>
        <li>Detecting and filtering crawlers and scraper bots to protect your campaign.</li>
        <li>Attributing conversions from affiliate postbacks to the original advertising click.</li>
        <li>Forwarding conversion events to your configured ad networks (Meta CAPI, Google Ads API, TikTok Events API).</li>
      </ul>

      <h2>3. Data Protection & SHA-256 Hashing</h2>
      <p>Privacy is our core feature:</p>
      <ul>
        <li><strong>One-Way Hash Protection:</strong> Any customer data received in conversions (such as emails or phone numbers) is instantly hashed using the SHA-256 algorithm before storage or transmission to third-party ad networks. We never store plaintext customer data.</li>
        <li><strong>AES-256 Encryption:</strong> All sensitive credentials (ad account tokens, integration secrets) are encrypted at rest using industry-standard AES-256 encryption.</li>
      </ul>

      <h2>4. Retention & Deletion</h2>
      <p>Raw click logs and IP caches are automatically purged after 7 to 30 days. You can request full account deletion at any time by contacting our support team.</p>

      <h2>5. Contact Us</h2>
      <p>If you have any questions regarding this Privacy Policy, please contact us at support@postbackflow.com.</p>
    <?php endif; ?>
  </div>

  <footer>
    <p>© <?= date('Y') ?> PostbackFlow. All rights reserved.</p>
  </footer>
</div>
</body>
</html>
