import React from 'react';
import { WebView } from 'react-native-webview';
import { View } from '@tamagui/core';
import { router } from 'expo-router';

//自定义组件
import { CustomSafeArea } from '@/components/common/CustomSafeArea';
import { CustomHeader } from '@/components/common/CustomHeader';

// 引入国际化
import { useTranslation } from 'react-i18next';
import i18n from '@/i18n';

import * as Application from 'expo-application';
import Constants from 'expo-constants';
import * as Updates from 'expo-updates';
//获取应用名称
const appName =
    Updates.manifest?.extra?.displayAppName ??
    Constants.expoConfig?.extra?.displayAppName ??
    Constants.expoConfig?.name ??
    Application.nativeApplicationName ?? '';

const DeleteAccountAgreement = () => {
    // 国际化
    const { t } = useTranslation('personal');

    // 简体中文HTML内容
    const htmlTxt = `
    <html>
      <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style>
          body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            line-height: 1.6;
            color: #333;
            padding: 16px;
            margin: 0;
          }
          h1, h2, h3 {
            color: #2c3e50;
          }
          p {
            margin-bottom: 12px;
          }
          ol, ul {
            padding-left: 20px;
          }
          li {
            margin-bottom: 8px;
          }
        </style>
      </head>
      <body>
        <p><strong>${appName}软件帐号注销协议</strong></p>
        <p>尊敬的用户，在您正式开始下一步有关${appName}软件帐号注销流程前，我们先为您做出如下特别说明：注销本${appName}帐号后，除法律法规另有规定外，您在该${appName}帐号下的个人信息将进行删除或匿名化处理，且此前已关联该${appName}帐号的相关产品与服务将不再关联。该${appName}帐号一旦注销完成，将无法恢复，请您谨慎操作。</p>
        <p>若您经过慎重考虑后仍执意决定注销本${appName}帐号的，请您务必先行仔细阅读和充分理解本《${appName}软件帐号注销协议》（“本协议”），并同意本协议全部内容。您按照我们的注销操作流程开始注销流程的，或者您勾选本注销协议并开始下一步操作的，均视为您已经同意和遵守本协议全部内容。</p>
        <p>如您在注销后需要再次使用我们的服务的，欢迎您使用${appName}提供的登录方式重新注册登录。</p>
        <p><strong>一、您知悉并同意：</strong>在您的${appName}帐号注销后，将（可能）产生包括但不限于如下结果，并需要您自行承担：</p>
        <ol>
          <li>您将无法登录、使用该${appName}帐号；</li>
          <li>如您曾使用同一帐号通过不同设备登录${appName}，则您的其他设备上的${appName}帐号一并注销，相关个人信息也一并被删除或匿名化处理；</li>
          <li>除法律法规另有规定外，您该${appName}帐号下的个人信息将会被删除或匿名化处理。您无法再找回您的个人信息，也无权要求我们找回，前述个人信息包括但不限于：头像昵称等个人资料信息、收藏记录、历史记录、随手拍发布信息、浏览记录、关联帐号信息、第三方关联数据等信息；</li>
          <li>一旦您同意本协议或您注销本${appName}帐号的，即视为您放弃该${appName}帐号在本${appName}使用期间已产生的及未来可能产生的${appName}权益，我们有权对该${appName}帐号下的全部${appName}权益做清除处理；</li>
          <li>本${appName}帐号一旦注销，将无法恢复。即使您在注销后以相同或其他我们提供的登录方式作为${appName}帐号再次向我们申请注册登录本${appName}的，此时该帐号将为新的用户帐号。因此，我们善意地提醒您在申请注销前对需要备份的内容提前做好备份。同时，也建议您在申请注销前清除系统缓存；</li>
          <li>本协议所涉帐号一旦注销，您与我们签署的有关本${appName}的《${appName}软件用户使用协议》（“用户协议”）终止（但已约定继续生效的除外）。但用户协议的终止并不影响${appName}帐号注销前您使用本${appName}服务应当承担的相关责任，您仍需要对${appName}帐号注销前使用本${appName}服务的行为承担相应责任，包括但不限于可能产生的违约责任、损害赔偿责任及履约义务等；</li>
          <li>其他因帐号注销（可能）产生的结果。</li>
        </ol>
        <p><strong>二、在您向我们申请/继续申请注销${appName}帐号之前，</strong>为保障您的帐号安全和相关权益，您需先行检查与确保您申请注销的${appName}帐号已经同时满足以下条件，这些条件包括但不限于：</p>
        <ol>
          <li>该${appName}帐号为您本人合法拥有并登录使用，且符合用户协议及相关说明规则中有关${appName}帐号的规定；</li>
          <li>该${appName}帐号处于安全状态：帐号为正常使用中且无违规、被封、被盗等情形；</li>
          <li>该${appName}帐号中的相关${appName}权益（见本协议第一条第4款）已结清或得到妥善处理，请您妥善处理您的${appName}权益，可待相关权益使用完毕后再进行注销，若您未予以处理且继续进行${appName}帐号注销流程，视为您自愿放弃该等${appName}权益；</li>
          <li>该${appName}帐号无任何纠纷：包括投诉举报、被投诉举报、国家机关调查、仲裁、诉讼等纠纷。</li>
        </ol>
        <p>上述问题您可首先尝试自行处理，如您无法处理的或在处理过程中有任何疑惑的，可联系我们客服协助处理。</p>
        <p><strong>三、如何注销${appName}帐号？</strong></p>
        <ol>
          <li>您需按照我们的官方渠道提供的注销流程和操作指引，在相关功能设置页面进行注销申请操作；</li>
          <li>您已经同意本注销协议的全部内容；同时，您已经检查与确认满足了本协议第二条的要求；</li>
          <li>在您完成上述第2点后，为进一步保障您的相关合法权益，我们有权但没有义务根据您的帐号安全状态以及您的相关服务的使用情况等综合判断您的帐号是否符合注销条件。为保障您的帐号安全和财产权益，我们有权进行注销申请的身份验证以判断您是该${appName}帐号的有权使用人（如由您提供操作相关信息供我们核实等）。如我们在综合判断后发现该${appName}帐号不符合注销条件的，或者身份验证失败的，您的注销可能会失败，您可以按照我们的指引进行后续操作或联系客服协助处理。即使我们判断您符合注销条件的，也是基于您的承诺（即您自身确保${appName}帐号符合上述注销条件的承诺）进行的形式审查，仍由您自身对${appName}帐号符合上述注销条件承担保证责任，我们对此不承担相应的法律责任；</li>
          <li>我们在您成功完成上述第3点的身份验证后，视为您已成功向我们提交了帐号注销申请，该帐号将永久注销。</li>
        </ol>
        <p>具体的注销流程和操作以${appName}官方公布的为准。您理解并同意，如我们需要对相关信息、投诉或其他与您的帐号相关的事项进行核实的，或者我们有其他合理的理由的，我们有权冻结您的该帐号且暂时不为您提供注销服务。</p>
        <p><strong>四、其他</strong></p>
        <p>本协议为用户协议组成部分，本协议未尽事宜适用用户协议。本协议与用户协议不一致的，以本协议为准。同时，您知悉并同意：即使您该${appName}帐号被注销，也并不减轻或免除您应根据相关法律法规、相关协议、规则等（可能）需要承担的相关责任。</p>
        <p>如在帐号注销过程中有任何问题您无法处理的或在处理过程中有任何疑惑的，可联系客服协助处理，我们承诺在15个工作日内，审核您所涉问题，并在验证您的用户身份后予以回复。</p>
        <p>客服电话：18051299227 / 18913689855</p>
        <p>FiEE(HK) Limited</p>
      </body>
    </html>
  `;

    // 英文HTML内容
    const htmlEnTxt = `
    <html>
      <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style>
          body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            line-height: 1.6;
            color: #333;
            padding: 16px;
            margin: 0;
          }
          h1, h2, h3 {
            color: #2c3e50;
          }
          p {
            margin-bottom: 12px;
          }
          ol, ul {
            padding-left: 20px;
          }
          li {
            margin-bottom: 8px;
          }
        </style>
      </head>
      <body>
        <p><strong>${appName} Account Deletion Agreement</strong></p>
        <p>Dear user, before you proceed with the account deletion process for your ${appName} account, please note: after your ${appName} account is deleted, unless otherwise required by laws and regulations, the personal information under this account will be deleted or anonymized, and products and services previously associated with this account will no longer be associated. Once deleted, the account cannot be recovered. Please proceed with caution.</p>
        <p>If after careful consideration you still decide to delete your ${appName} account, please read and fully understand this “${appName} Account Deletion Agreement” (this “Agreement”) and agree to all of its terms. By following our deletion operation process to start the deletion, or by checking this Agreement and proceeding to the next step, you are deemed to have agreed to and will comply with this Agreement in full.</p>
        <p>If you need to use our services again after deletion, you are welcome to register and log in again using the login methods provided by ${appName}.</p>
        <p><strong>1. You acknowledge and agree:</strong> After your ${appName} account is deleted, the following results may occur, which you will bear on your own:</p>
        <ol>
          <li>You will no longer be able to log in to or use this ${appName} account;</li>
          <li>If you have logged in to ${appName} with the same account on different devices, the account on your other devices will be deleted together, and related personal information will be deleted or anonymized together;</li>
          <li>Unless otherwise required by laws and regulations, the personal information under this account will be deleted or anonymized. You will not be able to retrieve your personal information, nor can you require us to retrieve it. Such information includes but is not limited to: profile information such as avatar and nickname, favorites, history, posts, browsing records, linked accounts, and third-party associated data;</li>
          <li>Once you agree to this Agreement or delete this ${appName} account, you are deemed to have waived the rights and interests generated during and potentially to be generated in the future under this account in ${appName}. We have the right to clear all such rights and interests under this account;</li>
          <li>Once the account is deleted, it cannot be restored. Even if you apply to register and log in to ${appName} again using the same or another login method after deletion, the account will be a new user account. Therefore, we kindly remind you to back up content that needs to be retained before applying for deletion, and we also recommend clearing system cache before applying;</li>
          <li>Once the account mentioned in this Agreement is deleted, the “${appName} User Agreement” entered into between you and us shall be terminated (except for the terms that are agreed to continue to be effective). The termination of the User Agreement does not affect your responsibilities arising from your use of ${appName} services before account deletion, including but not limited to possible liabilities for breach, damages, and obligations of performance;</li>
          <li>Other consequences that may be caused by account deletion.</li>
        </ol>
        <p><strong>2. Before you apply/continue to apply to delete your ${appName} account,</strong> to protect your account security and related rights and interests, please check and ensure that the account satisfies the following conditions, including but not limited to:</p>
        <ol>
          <li>The account is legally owned and used by you and complies with the provisions regarding ${appName} accounts in the User Agreement and relevant rules;</li>
          <li>The account is in a secure state: it is in normal use and not in violation, blocked, or stolen;</li>
          <li>The rights and interests related to the account in ${appName} (see Item 4 of Section 1 of this Agreement) have been settled or properly handled. You may handle your rights and interests and then proceed with deletion after use. If you continue the deletion process without handling them, it shall be deemed that you voluntarily waive such rights and interests;</li>
          <li>The account has no disputes: including complaints, being complained of, investigations by government agencies, arbitration, litigation, or other disputes.</li>
        </ol>
        <p>You may first try to resolve the above issues by yourself. If you cannot resolve them or have any questions during the process, you can contact our customer service for assistance.</p>
        <p><strong>3. How to delete the ${appName} account?</strong></p>
        <ol>
          <li>Follow the deletion process and operational guidelines provided through our official channels, and initiate a deletion application on the relevant settings page;</li>
          <li>You have agreed to all the terms of this Agreement, and you have checked and confirmed that you meet the requirements of Section 2 of this Agreement;</li>
          <li>After completing the above item 2, to further protect your lawful rights and interests, we have the right but not the obligation to comprehensively determine whether your account meets the deletion conditions based on your account security status and your use of related services. To protect your account security and property rights, we may conduct identity verification for the deletion application to determine whether you are the authorized user of the account (for example, by requesting that you provide operation-related information for our verification). If, after comprehensive judgment, we find that the account does not meet the conditions for deletion, or identity verification fails, the deletion may fail. You can follow our guidance for subsequent operations or contact customer service for assistance. Even if we determine that you meet the deletion conditions, it is based on your commitment (i.e., your own assurance that the account complies with the deletion conditions) and a formality review. You remain responsible for ensuring compliance, and we do not bear corresponding legal responsibilities;</li>
          <li>After you successfully complete the identity verification in item 3 above, you are deemed to have successfully submitted the account deletion application, and the account will be permanently deleted.</li>
        </ol>
        <p>The specific deletion process and operations are subject to the official announcements of ${appName}. You understand and agree that if we need to verify relevant information, complaints, or other matters related to your account, or if we have other reasonable reasons, we have the right to freeze your account and temporarily not provide deletion services.</p>
        <p><strong>4. Others</strong></p>
        <p>This Agreement constitutes part of the User Agreement. For matters not covered herein, the User Agreement shall apply. In case of any inconsistency between this Agreement and the User Agreement, this Agreement shall prevail. You also understand and agree that the deletion of your ${appName} account does not reduce or exempt any responsibilities that you may need to bear under applicable laws and regulations, relevant agreements, and rules.</p>
        <p>If you have any issues that you cannot handle during the account deletion process or have any questions during the process, you can contact customer service for assistance. We promise to review the issues involved within 15 business days and reply after verifying your user identity.</p>
        <p>Customer Service: 18051299227 / 18913689855</p>
        <p>FiEE(HK) Limited</p>
      </body>
    </html>
  `;

    // 繁体中文HTML内容
    const htmlTwTxt = `
    <html>
      <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style>
          body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            line-height: 1.6;
            color: #333;
            padding: 16px;
            margin: 0;
          }
          h1, h2, h3 {
            color: #2c3e50;
          }
          p {
            margin-bottom: 12px;
          }
          ol, ul {
            padding-left: 20px;
          }
          li {
            margin-bottom: 8px;
          }
        </style>
      </head>
      <body>
        <p><strong>${appName}軟體帳號註銷協議</strong></p>
        <p>尊敬的使用者，在您正式開始下一步有關 ${appName} 帳號註銷流程前，請先特別注意：註銷本 ${appName} 帳號後，除法律法規另有規定外，您在該帳號下的個人資訊將被刪除或匿名化處理，且此前已關聯該帳號的相關產品與服務將不再關聯。該帳號一旦註銷完成，將無法恢復，請您審慎操作。</p>
        <p>若您經過慎重考慮後仍決定註銷本 ${appName} 帳號，請您務必先行仔細閱讀並充分理解本《${appName}軟體帳號註銷協議》（「本協議」），並同意本協議全部內容。您依照我們的註銷操作流程開始註銷流程，或勾選本協議並開始下一步操作的，均視為您已同意並遵守本協議全部內容。</p>
        <p>如您在註銷後需要再次使用我們的服務，歡迎您使用 ${appName} 提供的登入方式重新註冊登入。</p>
        <p><strong>一、您知悉並同意：</strong>在您的 ${appName} 帳號註銷後，將（可能）產生包括但不限於如下結果，並由您自行承擔：</p>
        <ol>
          <li>您將無法登入或使用該 ${appName} 帳號；</li>
          <li>如您曾以同一帳號於不同裝置登入 ${appName}，則您於其他裝置上的該帳號將一併註銷，相關個人資訊亦將一併刪除或匿名化處理；</li>
          <li>除法律法規另有規定外，該帳號下的個人資訊將被刪除或匿名化。您無法再找回您的個人資訊，亦無權要求我們找回，前述個人資訊包括但不限於：頭像暱稱等個人資料、收藏記錄、歷史記錄、發布內容、瀏覽記錄、關聯帳號、第三方關聯資料等；</li>
          <li>一旦您同意本協議或註銷該 ${appName} 帳號，即視為您放棄該帳號在 ${appName} 使用期間已產生及未來可能產生的相關權益；我們有權對該帳號下全部權益進行清除處理；</li>
          <li>該帳號一旦註銷，將無法恢復。即使您於註銷後以相同或其他我們提供的登入方式再度申請註冊登入 ${appName}，該帳號亦為全新使用者帳號。故我們善意提醒您於申請註銷前，請先備份需保留之內容，並建議於申請註銷前清除系統快取；</li>
          <li>本協議所涉帳號一旦註銷，您與我們簽署之《${appName}軟體使用者使用協議》（「使用者協議」）終止（已約定繼續生效者除外）。惟使用者協議之終止並不影響您於註銷前使用 ${appName} 服務所應承擔之相關責任，包括但不限於可能產生之違約責任、損害賠償責任及履約義務等；</li>
          <li>其他因帳號註銷（可能）產生之結果。</li>
        </ol>
        <p><strong>二、在您向我們申請／繼續申請註銷 ${appName} 帳號之前，</strong>為保障您的帳號安全與相關權益，您需先行檢查並確保擬註銷之帳號已同時符合以下條件，包含但不限於：</p>
        <ol>
          <li>該帳號為您本人合法擁有並登入使用，且符合使用者協議及相關規則中關於 ${appName} 帳號之規定；</li>
          <li>該帳號處於安全狀態：帳號為正常使用中且無違規、被封、被盜等情形；</li>
          <li>該帳號中的相關權益（見本協議第一條第4款）已結清或妥善處理。請您妥善處理您的權益，待相關權益使用完畢後再進行註銷；若您未處理且繼續進行註銷流程，視為您自願放棄該等權益；</li>
          <li>該帳號無任何糾紛：包括投訴檢舉、被投訴檢舉、國家機關調查、仲裁、訴訟等糾紛。</li>
        </ol>
        <p>上述問題您可先嘗試自行處理；如無法處理或在處理過程中有任何疑問，得聯繫客服協助處理。</p>
        <p><strong>三、如何註銷 ${appName} 帳號？</strong></p>
        <ol>
          <li>您需依我們官方渠道提供之註銷流程與操作指引，於相關功能設定頁面進行註銷申請操作；</li>
          <li>您已同意本註銷協議全部內容，並已檢查與確認符合本協議第二條之要求；</li>
          <li>在您完成上述第2點後，為進一步保障您的合法權益，我們有權但無義務，依據您的帳號安全狀態及相關服務之使用情形，綜合判斷您的帳號是否符合註銷條件。為保障您的帳號安全與財產權益，我們有權進行註銷申請之身分驗證，以判斷您是否為該帳號之有權使用人（例如請您提供操作相關資訊供我們核實等）。如經綜合判斷後發現該帳號不符合註銷條件，或身分驗證失敗者，您的註銷可能失敗；您可依我們之指引進行後續操作或聯繫客服協助處理。即使我們判斷您符合註銷條件，亦係基於您的承諾（即您自行確保該帳號符合上述註銷條件之承諾）所為形式審查，相關法律責任仍由您自行承擔；</li>
          <li>我們在您成功完成上述第3點之身分驗證後，視為您已成功向我們提交帳號註銷申請，該帳號將永久註銷。</li>
        </ol>
        <p>具體註銷流程與操作以 ${appName} 官方公布為準。您理解並同意，如我們需要對相關資訊、投訴或其他與您的帳號相關之事項進行核實，或我們有其他合理之理由，我們有權凍結您的帳號並暫不提供註銷服務。</p>
        <p><strong>四、其他</strong></p>
        <p>本協議為使用者協議之組成部分；本協議未盡事宜，適用使用者協議。本協議與使用者協議不一致時，以本協議為準。您亦知悉並同意：即使您的 ${appName} 帳號被註銷，亦不免除您依相關法律法規、相關協議、規則等（可能）需承擔之責任。</p>
        <p>如於帳號註銷過程中有任何無法自行處理之問題，或於處理過程中有任何疑問，得聯繫客服協助處理。我們承諾於15個工作日內審核您所涉問題，並於驗證您的使用者身分後予以回覆。</p>
        <p>客服電話：18051299227 / 18913689855</p>
        <p>FiEE(HK) Limited</p>
      </body>
    </html>
  `;

    // 根据语言选择对应的HTML内容
    const getHtmlContent = () => {
        switch (i18n.language) {
            case 'en':
                return htmlEnTxt;
            case 'zh-TW':
                return htmlTwTxt;
            default:
                return htmlTxt;
        }
    };

    return (
        <CustomSafeArea>
            <CustomHeader
                title={t('signOut.deleteAccountAgreement')}
                onBack={() => router.back()}
            />
            <View flex={1}>
                <WebView
                    source={{ html: getHtmlContent() }}
                    style={{ flex: 1 }}
                    showsVerticalScrollIndicator={false}
                />
            </View>
        </CustomSafeArea>
    );
};

export default DeleteAccountAgreement;