"use client";

import { useLocale } from "@/i18n/navigation";

function renderWithLinks(text: string) {
  const urlRegex = /(https?:\/\/[^\s)]+)/g;
  const parts = text.split(urlRegex);
  return parts.map((part, i) =>
    part.match(urlRegex) ? (
      <a
        key={`${i}-${part}`}
        href={part}
        target="_blank"
        rel="noopener noreferrer"
        className="text-sky-600 underline hover:text-sky-700 dark:text-sky-400 dark:hover:text-sky-300"
      >
        {part}
      </a>
    ) : (
      part
    )
  );
}

const PRIVACY_ZH = {
  title: "隐私政策",
  lastUpdated: "最后更新",
  sections: [
    {
      title: "一、适用范围",
      content: `本隐私政策适用于「数字游民指南」（以下简称本网站）在您使用网站服务时收集的个人信息。本政策不适用于本网站以外的第三方链接网站，也不适用于非本网站委托或参与管理的人员。`,
    },
    {
      title: "二、个人资料的收集、处理及利用",
      content: `当您访问本网站或使用本网站提供的功能服务时，我们将根据服务性质请您提供必要的个人资料，并在特定目的范围内处理及利用；未经您书面同意，本网站不会将个人资料用于其他用途。

本网站在您使用申请表单、问卷、支付等互动功能时，会保留您提供的姓名、电子邮箱、联系方式及使用时间等。

在一般浏览时，服务器会自动记录相关行为，包括您使用设备的 IP 地址、使用时间、浏览器类型、浏览及点击记录等，作为我们改进网站服务的参考，此记录仅供内部使用，不会对外公布。

您可以随时向我们提出请求，以更正或删除您的账户或本网站所收集的个人资料。联系方式请见文末。`,
    },
    {
      title: "三、支付处理与 Stripe",
      content: `本网站使用 Stripe 作为支付服务提供商处理付款。在您进行支付时：

• 数据控制者：本网站为个人数据的控制者，Stripe 作为数据处理者代表我们处理支付相关数据。
• Stripe 隐私政策：您可查阅 Stripe 的隐私政策 https://stripe.com/privacy
• 收集的数据类别：Stripe 直接收集的数据包括卡号、有效期等支付信息及设备数据；我们向 Stripe 共享的数据包括邮箱、姓名、账单地址等完成交易所需信息。
• 国际数据传输：支付数据可能传输至美国等地区，Stripe 采用标准合同条款及欧盟-美国数据隐私框架等机制保障合规。
• 法律依据：支付处理基于合同履行（完成支付义务）、法律义务（税务与会计要求）及合法利益（欺诈防范）。
• 数据保留：交易记录通常保留 7–10 年以满足税务及会计要求；支付失败日志可能保留 90 天至 1 年。`,
    },
    {
      title: "四、资料保护",
      content: `本网站主机设有防火墙、防毒系统等安全设备及必要防护措施，保护网站及您的个人资料。个人资料仅由经授权人员接触，相关处理人员均签署保密协议，违反者将承担法律责任。

如因业务需要委托其他单位提供服务，本网站将严格要求其遵守保密义务，并采取必要检查程序确保其切实遵守。`,
    },
    {
      title: "五、外部链接",
      content: `本网站提供其他网站的链接，您可经由本网站提供的链接进入其他网站。该等链接网站不适用本网站的隐私政策，您须参考该链接网站自身的隐私政策。`,
    },
    {
      title: "六、与第三人共用个人资料",
      content: `本网站不会提供、交换、出租或出售您的个人资料给其他个人、团体、私人企业或公务机关，但有法律依据或合约义务者不在此限，包括但不限于：经您书面同意、法律明文规定、为免除您生命身体自由或财产上之危险、与公务机关或学术研究机构基于公共利益进行统计或学术研究且资料经处理后无法识别特定当事人、或为辨识联络或采取法律行动所必要者。

本网站委托厂商协助收集、处理或利用您的个人资料时，将对委外厂商善尽监督管理之责。`,
    },
    {
      title: "七、Cookie 使用",
      content: `为提供您最佳服务，本网站会在您的设备中放置并读取 Cookie。若您不愿接受 Cookie，可在浏览器中设定较高的隐私等级以拒绝 Cookie，但可能导致网站部分功能无法正常执行。`,
    },
    {
      title: "八、政策修订",
      content: `本隐私政策将因应需求随时修正，修正后的条款将刊登于本网站。`,
    },
    {
      title: "九、联系管道",
      content: `若对本隐私政策有任何疑问，或欲提出变更、删除个人资料之请求，请前往本网站「联系我们」页面提交表单，或通过以下方式联系我们：

• 网站：数字游民指南
• 邮箱：请通过网站联系我们页面获取
• 地址：请通过网站联系我们页面获取`,
    },
  ],
};

const PRIVACY_EN = {
  title: "Privacy Policy",
  lastUpdated: "Last updated",
  sections: [
    {
      title: "1. Scope",
      content: `This Privacy Policy applies to personal information collected by "Digital Nomad Guide" (the "Site") when you use our services. This policy does not apply to third-party websites linked from this Site, nor to persons not entrusted or involved in the management of this Site.`,
    },
    {
      title: "2. Collection, Processing and Use of Personal Data",
      content: `When you visit the Site or use our services, we may ask you to provide necessary personal data for specific purposes. We will not use your personal data for other purposes without your written consent.

When you use application forms, surveys, payments, or other interactive features, we retain information you provide, such as name, email, contact details, and usage time.

During general browsing, our servers automatically record relevant activity, including your IP address, access time, browser type, and browsing/click records, for improving our services. Such records are for internal use only and are not disclosed to the public.

You may request correction or deletion of your account or personal data collected by the Site at any time. Contact details are provided at the end of this policy.`,
    },
    {
      title: "3. Payment Processing and Stripe",
      content: `We use Stripe as our payment service provider. When you make a payment:

• Data Controller: We are the data controller; Stripe acts as a data processor on our behalf.
• Stripe Privacy Policy: https://stripe.com/privacy
• Data Categories: Stripe directly collects payment card details and device data; we share email, name, billing address, and other information necessary to complete the transaction.
• International Transfers: Payment data may be transferred to the US and other regions. Stripe uses Standard Contractual Clauses and the EU-US Data Privacy Framework to ensure compliance.
• Legal Basis: Payment processing is based on contract performance (fulfilling payment obligations), legal obligation (tax and accounting requirements), and legitimate interest (fraud prevention).
• Data Retention: Transaction records are typically retained for 7–10 years for tax and accounting purposes; payment failure logs may be retained for 90 days to 1 year.`,
    },
    {
      title: "4. Data Protection",
      content: `Our servers are protected by firewalls, antivirus systems, and other security measures. Personal data is accessible only to authorized personnel who have signed confidentiality agreements. Violations will result in legal liability.

When we entrust third parties to process personal data, we require them to comply with confidentiality obligations and conduct necessary audits.`,
    },
    {
      title: "5. External Links",
      content: `The Site provides links to other websites. Those linked sites are not governed by this Privacy Policy. Please refer to the privacy policy of each linked site.`,
    },
    {
      title: "6. Sharing Personal Data with Third Parties",
      content: `We will not provide, exchange, rent, or sell your personal data to other individuals, groups, or entities, except where required by law or contract, including but not limited to: your written consent, legal requirements, protection of life or property, statistical or academic research with anonymized data, or identification/contact/legal action as necessary.

When we entrust third parties to collect, process, or use your personal data, we will supervise them appropriately.`,
    },
    {
      title: "7. Use of Cookies",
      content: `To provide you with the best service, we place and read cookies on your device. You may set a higher privacy level in your browser to refuse cookies, but some features of the Site may not function properly.`,
    },
    {
      title: "8. Policy Amendments",
      content: `We may amend this Privacy Policy from time to time. Amended terms will be posted on the Site.`,
    },
    {
      title: "9. Contact",
      content: `If you have questions about this Privacy Policy or wish to request correction or deletion of your personal data, please submit a form via our "Contact Us" page, or contact us through:

• Site: Digital Nomad Guide
• Email: Available via the Contact Us page
• Address: Available via the Contact Us page`,
    },
  ],
};

export default function PrivacyContent() {
  const locale = useLocale();
  const content = locale === "zh" ? PRIVACY_ZH : PRIVACY_EN;

  return (
    <div className="min-h-screen bg-slate-50 py-16 dark:bg-slate-950 sm:py-20">
      <div className="mx-auto max-w-3xl px-4 sm:px-6 lg:px-8">
        <h1 className="text-3xl font-bold tracking-tight text-slate-900 dark:text-slate-100 sm:text-4xl">
          {content.title}
        </h1>
        <p className="mt-2 text-sm text-slate-500 dark:text-slate-400">
          {content.lastUpdated}: 2025-03
        </p>

        <div className="mt-10 space-y-10">
          {content.sections.map((section) => (
            <section key={section.title}>
              <h2 className="mb-4 text-lg font-bold text-slate-900 dark:text-slate-100">
                {section.title}
              </h2>
              <div className="whitespace-pre-line text-slate-600 dark:text-slate-400">
                {renderWithLinks(section.content)}
              </div>
            </section>
          ))}
        </div>
      </div>
    </div>
  );
}
