/* global React */
const { useState, useEffect } = React;

/* ============================================================
   LEGAL PAGES — Terms & Conditions + Privacy Policy
   Bilingual (English / العربية) with an in-page toggle. Only the
   legal article flips to RTL — the shared Nav/Footer stay LTR.

   Content is tailored to Wathiq (Saudi legal-AI SaaS) and the
   Saudi Personal Data Protection Law (PDPL). The privacy posture
   (controller/processor split, retention table, cross-border
   OpenAI/Anthropic disclosure under PDPL Art. 29, DPO contact)
   mirrors the in-app policy in wathiq-web so the two never drift.

   NOTE: professional drafting — still subject to DPO / external
   counsel sign-off before being relied upon. Commercial terms
   (fees, term length) live in each customer's Order Form, which
   prevails over the marketing terms below to the extent of conflict.
   ============================================================ */

// Use the GLOBAL site language (set by i18n.js / the head bootstrap) so the nav
// globe switch controls the legal pages too — one language control for the whole
// site. Default Arabic, like the rest of the site.
function useLegalLang() {
  const lang = (typeof window !== "undefined" && window.WATHIQ_LANG === "en") ? "en" : "ar";
  return [lang, function () {}];
}

function LangToggle({ lang, setLang }) {
  return (
    <div className="legal-lang" role="group" aria-label="Document language">
      <button type="button" className={lang === "en" ? "is-active" : ""}
        aria-pressed={lang === "en"} onClick={() => setLang("en")}>English</button>
      <button type="button" className={lang === "ar" ? "is-active" : ""}
        aria-pressed={lang === "ar"} onClick={() => setLang("ar")}>العربية</button>
    </div>
  );
}

function LegalBlocks({ blocks, isAr }) {
  return blocks.map((b, i) => {
    const v = isAr ? b.ar : b.en;
    switch (b.type) {
      case "lede":
        return <p className="legal-lede" key={i}>{v}</p>;
      case "p":
        return <p key={i}>{v}</p>;
      case "h3":
        return <h3 key={i}>{v}</h3>;
      case "ul":
        return <ul key={i}>{v.map((li, j) => <li key={j}>{li}</li>)}</ul>;
      case "note":
        return (
          <div className="legal-note" key={i}>
            {b.label && <span className="legal-note-label">{isAr ? b.label.ar : b.label.en}</span>}
            {v.map((p, j) => <p key={j}>{p}</p>)}
          </div>
        );
      case "table": {
        const head = isAr ? b.head.ar : b.head.en;
        return (
          <table className="legal-table" key={i}>
            <thead><tr>{head.map((h, j) => <th key={j}>{h}</th>)}</tr></thead>
            <tbody>
              {b.rows.map((r, j) => {
                const cells = isAr ? r.ar : r.en;
                return <tr key={j}>{cells.map((c, k) => <td key={k}>{c}</td>)}</tr>;
              })}
            </tbody>
          </table>
        );
      }
      default:
        return null;
    }
  });
}

function LegalPage({ eyebrow, title, updated, lede, sections }) {
  const [lang] = useLegalLang();
  const isAr = lang === "ar";
  const dir = isAr ? "rtl" : "ltr";
  return (
    <>
      <section className="legal-hero" dir={dir}>
        <div className="container legal-hero-inner">
          <span className="eyebrow">{isAr ? eyebrow.ar : eyebrow.en}</span>
          <h1>{isAr ? title.ar : title.en}</h1>
          <span className="legal-updated">{isAr ? updated.ar : updated.en}</span>
        </div>
      </section>
      <article className="legal-doc" dir={dir}>
        <div className="container">
          <div className="legal-body">
            {lede && <p className="legal-lede">{isAr ? lede.ar : lede.en}</p>}
            {sections.map((s, i) => (
              <section className="legal-section" id={s.id} key={s.id || i}>
                <h2>{isAr ? s.title.ar : s.title.en}</h2>
                <LegalBlocks blocks={s.blocks} isAr={isAr} />
              </section>
            ))}
          </div>
        </div>
      </article>
    </>
  );
}

/* ============================================================
   TERMS & CONDITIONS
   ============================================================ */

const TERMS_SECTIONS = [
  {
    id: "about",
    title: { en: "1. About these Terms", ar: "١. عن هذه الشروط" },
    blocks: [
      {
        type: "p",
        en: `These Terms & Conditions ("Terms") govern your access to and use of the Wathiq platform, the Wathiq Microsoft Word add-in, our application programming interfaces, and the websites at wathiq.ai (together, the "Service"), operated by Fares Ibrahim Alghamdi & Abdulrahman Yasser Osailan Company — a limited liability company incorporated in the Kingdom of Saudi Arabia, unified national number 7050363576 — ("Wathiq", "we", "us"). By accessing or using the Service, you agree to these Terms on behalf of yourself and the law firm or organisation you represent ("you").`,
        ar: `تحكم هذه الشروط والأحكام («الشروط») وصولك إلى منصة وثّق، وإضافة وثّق لبرنامج مايكروسوفت وورد، وواجهات البرمجة، والمواقع الإلكترونية على النطاق wathiq.ai (مجتمعةً «الخدمة»)، التي تشغّلها شركة فارس إبراهيم الغامدي وعبدالرحمن ياسر عسيلان — شركة ذات مسؤولية محدودة مؤسسة في المملكة العربية السعودية، الرقم الوطني الموحد 7050363576 — («وثّق» أو «نحن»). وباستخدامك للخدمة فإنك توافق على هذه الشروط بالأصالة عن نفسك وبالنيابة عن مكتب المحاماة أو الجهة التي تمثّلها («أنت»).`,
      },
      {
        type: "p",
        en: `If your firm has entered into a separate written subscription or master services agreement with Wathiq (an "Order Form"), that agreement governs your use of the Service and prevails over these Terms to the extent of any conflict. These Terms otherwise apply.`,
        ar: `إذا أبرم مكتبك اتفاقية اشتراك أو اتفاقية خدمات رئيسية مكتوبة منفصلة مع وثّق («نموذج الطلب»)، فإن تلك الاتفاقية تحكم استخدامك للخدمة وتسري على ما يتعارض معها من هذه الشروط. وفيما عدا ذلك تُطبَّق هذه الشروط.`,
      },
    ],
  },
  {
    id: "definitions",
    title: { en: "2. Definitions", ar: "٢. التعريفات" },
    blocks: [
      {
        type: "ul",
        en: [
          <><strong>Service / Platform</strong> — the Wathiq legal-AI workspace, including AI Lab, Vault, Knowledge, Matter management, Playbooks, Workflows, the Word add-in, and related features.</>,
          <><strong>Input</strong> — any text, document, file, or instruction you submit to the Service.</>,
          <><strong>Output</strong> — any content the Service generates in response to your Input.</>,
          <><strong>Customer Content</strong> — your Input and Output together, including the documents and matter data you upload.</>,
          <><strong>Usage Data</strong> — aggregated, de-identified data about how the Service is accessed and used (never the substance of your Customer Content).</>,
        ],
        ar: [
          <><strong>الخدمة / المنصة</strong> — مساحة عمل وثّق القانونية المدعومة بالذكاء الاصطناعي، وتشمل مختبر الذكاء الاصطناعي، والخزنة، والمعرفة، وإدارة القضايا، ودلائل العمل، وسير العمل، وإضافة وورد، والميزات ذات الصلة.</>,
          <><strong>المُدخلات</strong> — أي نص أو مستند أو ملف أو تعليمات تُرسلها إلى الخدمة.</>,
          <><strong>المُخرجات</strong> — أي محتوى تُنتجه الخدمة استجابةً لمُدخلاتك.</>,
          <><strong>محتوى العميل</strong> — مُدخلاتك ومُخرجاتك مجتمعةً، بما في ذلك المستندات وبيانات القضايا التي ترفعها.</>,
          <><strong>بيانات الاستخدام</strong> — بيانات مجمَّعة ومجهَّلة عن كيفية الوصول إلى الخدمة واستخدامها (لا تشمل مضمون محتوى العميل).</>,
        ],
      },
    ],
  },
  {
    id: "service",
    title: { en: "3. The Service", ar: "٣. الخدمة" },
    blocks: [
      {
        type: "p",
        en: `Wathiq is an AI-assisted legal workspace built for Saudi law firms and in-house legal teams. It helps you research Saudi law, analyse and draft documents, manage matters, and codify your firm's standards into reusable workflows. The Service is provided as software-as-a-service over the web, through the Microsoft Word add-in, and through our APIs.`,
        ar: `وثّق مساحة عمل قانونية مدعومة بالذكاء الاصطناعي، مصمَّمة لمكاتب المحاماة والإدارات القانونية في المملكة العربية السعودية. تساعدك على البحث في الأنظمة السعودية، وتحليل المستندات وصياغتها، وإدارة القضايا، وتحويل معايير مكتبك إلى سير عمل قابل لإعادة الاستخدام. وتُقدَّم الخدمة بصيغة برمجيات كخدمة عبر الويب، وعبر إضافة مايكروسوفت وورد، وعبر واجهاتنا البرمجية.`,
      },
      {
        type: "p",
        en: `We may improve, add to, modify, or remove features of the Service from time to time. We will not make changes that materially reduce the core security or data-protection commitments described in these Terms or our Privacy Policy without notice.`,
        ar: `قد نُحسّن الخدمة أو نضيف إليها أو نعدّلها أو نزيل بعض ميزاتها من وقت لآخر. ولن نُجري تغييرات تُقلّص جوهرياً من الالتزامات الأساسية المتعلقة بالأمن أو حماية البيانات الموضّحة في هذه الشروط أو في سياسة الخصوصية دون إشعار.`,
      },
    ],
  },
  {
    id: "accounts",
    title: { en: "4. Eligibility & accounts", ar: "٤. الأهلية والحسابات" },
    blocks: [
      {
        type: "ul",
        en: [
          "The Service is for business use by legal professionals and their firms. You must be at least 18 years old and authorised to bind the organisation you represent.",
          "You are responsible for the security of your account credentials and for all activity under your account. Credentials are personal and must not be shared, rotated, or reassigned other than when a user leaves your firm.",
          "You must promptly notify us of any unauthorised access to or use of your account.",
        ],
        ar: [
          "الخدمة مخصصة للاستخدام المهني من قِبل المختصين القانونيين ومكاتبهم. ويجب ألا يقل عمرك عن ١٨ عاماً وأن تكون مفوَّضاً بإلزام الجهة التي تمثّلها.",
          "أنت مسؤول عن أمان بيانات اعتماد حسابك وعن جميع الأنشطة التي تتم من خلاله. وبيانات الاعتماد شخصية ولا يجوز مشاركتها أو تدويرها أو إعادة تخصيصها إلا عند مغادرة المستخدم لمكتبك.",
          "عليك إبلاغنا فوراً بأي وصول أو استخدام غير مصرَّح به لحسابك.",
        ],
      },
    ],
  },
  {
    id: "acceptable-use",
    title: { en: "5. Acceptable use", ar: "٥. الاستخدام المقبول" },
    blocks: [
      { type: "p", en: "You agree not to use the Service to:", ar: "توافق على عدم استخدام الخدمة في أيٍّ مما يلي:" },
      {
        type: "ul",
        en: [
          "Break any applicable law or regulation, or infringe the rights — including intellectual-property and privacy rights — of any third party.",
          "Reverse-engineer, decompile, scrape, or attempt to derive the source code or models of the Service, or circumvent its security or usage limits.",
          "Build or train a competing product or service, or resell, sublicense, or transfer access without our written consent.",
          "Upload malicious code, or interfere with or disrupt the integrity or performance of the Service.",
          "Submit special-category or sensitive personal data (for example health, biometric, genetic, or criminal-record data) except where your subscription expressly provides for it.",
          "Make legally or similarly significant decisions about individuals based solely on Output, without meaningful review by a qualified human.",
        ],
        ar: [
          "مخالفة أي نظام أو لائحة سارية، أو التعدّي على حقوق الغير — بما في ذلك حقوق الملكية الفكرية والخصوصية.",
          "الهندسة العكسية للخدمة أو فك ترجمتها أو كشطها أو محاولة استخراج شفرتها المصدرية أو نماذجها، أو الالتفاف على ضوابطها الأمنية أو حدود استخدامها.",
          "بناء أو تدريب منتج أو خدمة منافِسة، أو إعادة بيع الوصول إليها أو الترخيص من الباطن أو نقله دون موافقتنا الكتابية.",
          "رفع شفرات ضارة، أو التشويش على سلامة الخدمة أو أدائها أو تعطيلها.",
          "إدخال بيانات شخصية حساسة أو من الفئات الخاصة (مثل البيانات الصحية أو الحيوية أو الوراثية أو المتعلقة بالسوابق الجنائية) إلا حيث ينص اشتراكك على ذلك صراحةً.",
          "اتخاذ قرارات ذات أثر قانوني أو مماثل في الأهمية بشأن الأفراد بالاعتماد على المُخرجات وحدها دون مراجعة فعلية من مختص مؤهَّل.",
        ],
      },
    ],
  },
  {
    id: "no-legal-advice",
    title: { en: "6. AI output is not legal advice", ar: "٦. مُخرجات الذكاء الاصطناعي ليست استشارة قانونية" },
    blocks: [
      {
        type: "note",
        label: { en: "Important", ar: "تنبيه مهم" },
        en: [
          `Wathiq is a software provider, not a law firm. We do not practise law and do not provide legal advice, and no lawyer–client relationship is created between you and Wathiq.`,
          `Output is generated by AI models, is probabilistic, and may be inaccurate, incomplete, or out of date. You are solely responsible for exercising professional judgement and for the independent review and verification of all Output — including every citation, figure, and legal conclusion — by a qualified, licensed lawyer before it is relied upon or used.`,
        ],
        ar: [
          `وثّق مزوّدة برمجيات وليست مكتب محاماة. ولا نمارس المحاماة ولا نقدّم استشارات قانونية، ولا تنشأ بينك وبين وثّق أي علاقة محامٍ بموكّل.`,
          `تُنتَج المُخرجات بواسطة نماذج ذكاء اصطناعي وهي ذات طبيعة احتمالية، وقد تكون غير دقيقة أو ناقصة أو غير محدَّثة. وتتحمّل وحدك مسؤولية إعمال التقدير المهني والمراجعة والتحقق المستقلين من جميع المُخرجات — بما في ذلك كل إسناد ورقم واستنتاج قانوني — من قِبل محامٍ مؤهَّل ومرخَّص قبل الاعتماد عليها أو استخدامها.`,
        ],
      },
      {
        type: "p",
        en: `You remain responsible for compliance with your own professional and ethical obligations, including those of the Saudi Bar and any court or regulator before which you appear.`,
        ar: `تبقى مسؤولاً عن الوفاء بالتزاماتك المهنية والأخلاقية، بما في ذلك التزامات الهيئة السعودية للمحامين وأي جهة قضائية أو رقابية تَمثُل أمامها.`,
      },
    ],
  },
  {
    id: "your-content",
    title: { en: "7. Your content & AI training", ar: "٧. محتواك وتدريب النماذج" },
    blocks: [
      {
        type: "p",
        en: `As between you and Wathiq, you (and your firm and clients) retain all rights, title, and interest in your Customer Content. You grant Wathiq a limited, worldwide, non-exclusive licence to host, process, transmit, and display your Customer Content solely to provide, secure, and support the Service for you.`,
        ar: `فيما بينك وبين وثّق، تحتفظ أنت (ومكتبك وموكّلوك) بكامل الحقوق والملكية والمصلحة في محتوى العميل العائد لك. وتمنح وثّق ترخيصاً محدوداً وغير حصري وعالمي النطاق لاستضافة محتوى العميل ومعالجته ونقله وعرضه لغرض تقديم الخدمة وتأمينها ودعمها لك حصراً.`,
      },
      {
        type: "p",
        en: `Wathiq does not use your Customer Content to train or fine-tune its own or any third party's foundation AI models. We contractually require our AI sub-processors not to use your content to train their models, and we are putting enterprise (zero-retention) terms in place with each provider. Because the models are probabilistic, similar inputs from other customers may produce similar Output; Output is not guaranteed to be unique to you.`,
        ar: `لا تستخدم وثّق محتوى العميل العائد لك لتدريب نماذجها أو نماذج أي طرف ثالث أو ضبطها. ونشترط تعاقدياً على جهات المعالجة الفرعية للذكاء الاصطناعي عدم استخدام محتواك في تدريب نماذجها، ونعمل على ترتيب شروط مؤسسية (بعدم الاحتفاظ بالبيانات) مع كل مزوّد. ونظراً للطبيعة الاحتمالية للنماذج، قد تُنتج مُدخلات مشابهة من عملاء آخرين مُخرجات مشابهة؛ ولا يُضمَن تفرُّد المُخرجات لك.`,
      },
    ],
  },
  {
    id: "ip",
    title: { en: "8. Our intellectual property", ar: "٨. ملكيتنا الفكرية" },
    blocks: [
      {
        type: "p",
        en: `Wathiq and its licensors own all rights in the Service, including its software, model configuration, prompts, user interface, and all related intellectual property, together with all improvements to it. Except for the rights expressly granted to you, no rights are transferred. If you send us feedback or suggestions, you grant us a perpetual, royalty-free right to use them to improve the Service.`,
        ar: `تملك وثّق ومرخِّصوها جميع الحقوق في الخدمة، بما فيها برمجياتها وتهيئة نماذجها وأوامرها وواجهة استخدامها وكل ما يتصل بها من ملكية فكرية، إضافةً إلى كل ما يطرأ عليها من تحسينات. وباستثناء الحقوق الممنوحة لك صراحةً، لا تُنقَل أي حقوق. وإذا أرسلت إلينا ملاحظات أو اقتراحات، فإنك تمنحنا حقاً دائماً وبلا مقابل لاستخدامها في تحسين الخدمة.`,
      },
    ],
  },
  {
    id: "privacy",
    title: { en: "9. Privacy & data protection", ar: "٩. الخصوصية وحماية البيانات" },
    blocks: [
      {
        type: "p",
        en: <>Our processing of personal data is governed by the Saudi Personal Data Protection Law (PDPL) and described in our <a href="Privacy.html">Privacy Policy</a>. For Customer Content, Wathiq acts as a data processor on your firm's behalf under your subscription and data-processing terms. To deliver AI features, some text is processed by AI providers outside the Kingdom under appropriate contractual safeguards — this processing is disclosed in the Privacy Policy.</>,
        ar: <>تخضع معالجتنا للبيانات الشخصية لنظام حماية البيانات الشخصية السعودي، وهي موضّحة في <a href="Privacy.html">سياسة الخصوصية</a>. وفيما يخص محتوى العميل، تعمل وثّق بصفتها جهة معالجة بالنيابة عن مكتبك بموجب اشتراكك وشروط معالجة البيانات. ولتقديم ميزات الذكاء الاصطناعي، يُعالَج جزء من النص لدى مزوّدي نماذج خارج المملكة وفق ضمانات تعاقدية مناسبة — ويُفصَح عن هذه المعالجة في سياسة الخصوصية.</>,
      },
    ],
  },
  {
    id: "confidentiality",
    title: { en: "10. Confidentiality", ar: "١٠. السرية" },
    blocks: [
      {
        type: "p",
        en: `Each party will protect the other's confidential information with at least the same care it uses for its own, and will use it only as needed to perform under these Terms. Your Customer Content is your confidential information. These obligations do not apply to information that is public through no fault of the receiving party, or that must be disclosed by law (with notice where permitted).`,
        ar: `يلتزم كل طرف بحماية المعلومات السرية للطرف الآخر بالعناية ذاتها التي يحمي بها معلوماته على الأقل، ولا يستخدمها إلا بالقدر اللازم لتنفيذ هذه الشروط. ويُعدّ محتوى العميل العائد لك معلومةً سريةً تخصّك. ولا تسري هذه الالتزامات على المعلومات التي تصبح علنيةً دون خطأٍ من الطرف المتلقّي، أو التي يجب الإفصاح عنها بموجب النظام (مع الإشعار حيثما يُسمح بذلك).`,
      },
    ],
  },
  {
    id: "fees",
    title: { en: "11. Fees", ar: "١١. الرسوم" },
    blocks: [
      {
        type: "p",
        en: `Access to the Service is provided on a subscription basis. Fees, billing cycle, and term are set out in your Order Form. Unless stated otherwise, fees are exclusive of applicable taxes, including value-added tax (VAT), for which you are responsible.`,
        ar: `يُتاح الوصول إلى الخدمة على أساس الاشتراك. وتُحدَّد الرسوم ودورة الفوترة ومدة الاشتراك في نموذج الطلب. وما لم يُنص على خلاف ذلك، فإن الرسوم لا تشمل الضرائب المطبَّقة، بما فيها ضريبة القيمة المضافة، وتتحمّلها أنت.`,
      },
    ],
  },
  {
    id: "warranties",
    title: { en: "12. Warranties & disclaimers", ar: "١٢. الضمانات وإخلاء المسؤولية" },
    blocks: [
      {
        type: "p",
        en: `We provide the Service with reasonable skill and care. Except as expressly stated in these Terms or an Order Form, and to the maximum extent permitted by applicable law, the Service is provided "as is" and "as available". We do not warrant that the Service will be uninterrupted or error-free, or that Output will be accurate or complete, and we disclaim all implied warranties, including merchantability, fitness for a particular purpose, and non-infringement.`,
        ar: `نقدّم الخدمة بمهارة وعناية معقولتين. وباستثناء ما تنص عليه هذه الشروط أو نموذج الطلب صراحةً، وإلى أقصى حدٍّ يسمح به النظام الساري، تُقدَّم الخدمة «كما هي» و«حسب توافرها». ولا نضمن أن تكون الخدمة دون انقطاع أو خالية من الأخطاء، ولا أن تكون المُخرجات دقيقة أو كاملة، ونُخلي مسؤوليتنا من جميع الضمانات الضمنية، بما فيها القابلية للتسويق والملاءمة لغرض معيّن وعدم التعدّي.`,
      },
    ],
  },
  {
    id: "liability",
    title: { en: "13. Limitation of liability", ar: "١٣. حدّ المسؤولية" },
    blocks: [
      {
        type: "p",
        en: `To the maximum extent permitted by law, neither party will be liable for any indirect, incidental, special, or consequential loss, or for lost profits, revenue, data, or goodwill. Each party's total aggregate liability arising out of or relating to the Service will not exceed the fees you paid for the Service in the twelve (12) months before the event giving rise to the claim, or the amount set out in your Order Form. These limits do not apply to your payment obligations, a party's indemnification obligations, or liability that cannot be excluded under applicable law.`,
        ar: `إلى أقصى حدٍّ يسمح به النظام، لا يكون أي من الطرفين مسؤولاً عن أي خسارة غير مباشرة أو عرضية أو خاصة أو تبعية، ولا عن فوات الأرباح أو الإيرادات أو فقد البيانات أو السمعة التجارية. ولا تتجاوز المسؤولية الإجمالية لكل طرف الناشئة عن الخدمة أو المتصلة بها قيمة الرسوم التي دفعتها مقابل الخدمة خلال الاثني عشر (١٢) شهراً السابقة للحدث المنشئ للمطالبة، أو المبلغ المحدَّد في نموذج الطلب. ولا تسري هذه الحدود على التزاماتك بالسداد، أو التزامات أيٍّ من الطرفين بالتعويض، أو المسؤولية التي لا يجوز استبعادها بموجب النظام الساري.`,
      },
    ],
  },
  {
    id: "indemnity",
    title: { en: "14. Indemnification", ar: "١٤. التعويض" },
    blocks: [
      {
        type: "p",
        en: `You will defend and indemnify Wathiq against third-party claims arising from your Input, your Customer Content, or your use of the Service in breach of these Terms. Wathiq will defend and indemnify you against third-party claims that the Service, used as permitted, infringes that third party's intellectual-property rights. The party seeking indemnity must give prompt notice and reasonable cooperation, and the indemnifying party controls the defence and settlement.`,
        ar: `تلتزم بالدفاع عن وثّق وتعويضها عن مطالبات الغير الناشئة عن مُدخلاتك أو محتوى العميل العائد لك أو استخدامك للخدمة بما يخالف هذه الشروط. وتلتزم وثّق بالدفاع عنك وتعويضك عن مطالبات الغير التي تزعم أن الخدمة — عند استخدامها على النحو المسموح — تتعدّى على حقوق الملكية الفكرية لذلك الغير. وعلى الطرف الذي يطلب التعويض الإشعار الفوري والتعاون المعقول، ويتولى الطرف المُعوِّض إدارة الدفاع والتسوية.`,
      },
    ],
  },
  {
    id: "term",
    title: { en: "15. Term & termination", ar: "١٥. المدة والإنهاء" },
    blocks: [
      {
        type: "p",
        en: `These Terms apply for as long as you use the Service or have an active subscription. Either party may terminate for the other's material breach that is not cured within thirty (30) days of written notice. On termination, your right to use the Service ends; you may export your Customer Content for thirty (30) days, after which we securely delete or de-identify (pseudonymise) it within a reasonable period, except where retention is required by law, your firm's professional-record rules (commonly up to ~10 years), or our security and audit-log retention, in which case the retained content is isolated from further processing (see the Privacy Policy retention table). Provisions that by their nature should survive — including confidentiality, intellectual property, disclaimers, liability, and governing law — survive termination.`,
        ar: `تسري هذه الشروط طوال مدة استخدامك للخدمة أو وجود اشتراك فعّال لديك. ويجوز لأيٍّ من الطرفين الإنهاء عند إخلال الطرف الآخر إخلالاً جوهرياً لم يُعالَج خلال ثلاثين (٣٠) يوماً من الإشعار الكتابي. وعند الإنهاء ينتهي حقك في استخدام الخدمة؛ ويمكنك تصدير محتوى العميل العائد لك خلال ثلاثين (٣٠) يوماً، نحذفه بعدها أو نُزيل صفته التعريفية (بالتجهيل المستعار) بشكل آمن خلال مدة معقولة، إلا حيث يوجب الاحتفاظ به النظامُ أو قواعد الاحتفاظ بالسجلات المهنية لدى مكتبك (عادةً حتى نحو عشر سنوات) أو متطلبات الاحتفاظ بسجلات الأمن والتدقيق لدينا، وفي هذه الحال يُعزَل المحتوى المحتفظ به عن أي معالجة أخرى (انظر جدول الاحتفاظ في سياسة الخصوصية). وتبقى نافذةً بعد الإنهاء الأحكامُ التي تقتضي طبيعتها الاستمرار، ومنها السرية والملكية الفكرية وإخلاء المسؤولية وحدّ المسؤولية والنظام الواجب التطبيق.`,
      },
    ],
  },
  {
    id: "changes",
    title: { en: "16. Changes to these Terms", ar: "١٦. تعديل هذه الشروط" },
    blocks: [
      {
        type: "p",
        en: `We may update these Terms from time to time. If a change is material, we will take reasonable steps to notify you in advance. Your continued use of the Service after an update takes effect means you accept the updated Terms.`,
        ar: `قد نُحدّث هذه الشروط من وقت لآخر. وإذا كان التغيير جوهرياً، فسنتخذ خطوات معقولة لإشعارك مسبقاً. ويُعدّ استمرارك في استخدام الخدمة بعد نفاذ التحديث قبولاً منك للشروط المحدَّثة.`,
      },
    ],
  },
  {
    id: "law",
    title: { en: "17. Governing law & disputes", ar: "١٧. النظام الواجب التطبيق وتسوية النزاعات" },
    blocks: [
      {
        type: "p",
        en: `These Terms are governed by the laws and regulations of the Kingdom of Saudi Arabia. Any dispute arising out of or relating to the Service or these Terms that cannot be resolved amicably is subject to the jurisdiction of the competent courts of the Kingdom of Saudi Arabia. Where the Arabic and English versions of these Terms differ, the Arabic version prevails.`,
        ar: `تخضع هذه الشروط لأنظمة المملكة العربية السعودية ولوائحها. وأي نزاع ينشأ عن الخدمة أو هذه الشروط أو يتصل بها ولا يمكن تسويته ودياً يكون من اختصاص المحاكم المختصة في المملكة العربية السعودية. وعند اختلاف النصّين العربي والإنجليزي لهذه الشروط، يُعتدّ بالنص العربي.`,
      },
    ],
  },
  {
    id: "contact",
    title: { en: "18. Contact", ar: "١٨. التواصل" },
    blocks: [
      {
        type: "p",
        en: <>Questions about these Terms can be sent to <a href="mailto:info@wathiq.ai">info@wathiq.ai</a>.</>,
        ar: <>يمكن إرسال الاستفسارات حول هذه الشروط إلى <a href="mailto:info@wathiq.ai">info@wathiq.ai</a>.</>,
      },
    ],
  },
];

/* ============================================================
   PRIVACY POLICY
   ============================================================ */

const PRIVACY_SECTIONS = [
  {
    id: "who",
    title: { en: "1. Who we are & scope", ar: "١. من نحن ونطاق السياسة" },
    blocks: [
      {
        type: "p",
        en: `Wathiq ("we", "us") is a Saudi-headquartered legal-AI platform operated by Fares Ibrahim Alghamdi & Abdulrahman Yasser Osailan Company (a limited liability company, unified national number 7050363576), operating under the Saudi Personal Data Protection Law (PDPL). This Privacy Policy explains how we handle personal data collected through our website at wathiq.ai, our demo and contact forms, and our account onboarding — situations in which we act as the data controller.`,
        ar: `وثّق («وثّق» أو «نحن») منصة قانونية مدعومة بالذكاء الاصطناعي مقرّها المملكة العربية السعودية، تشغّلها شركة فارس إبراهيم الغامدي وعبدالرحمن ياسر عسيلان (شركة ذات مسؤولية محدودة، الرقم الوطني الموحد 7050363576)، وتعمل وفق نظام حماية البيانات الشخصية السعودي. وتوضّح سياسة الخصوصية هذه كيفية تعاملنا مع البيانات الشخصية التي نجمعها عبر موقعنا wathiq.ai، ونماذج طلب العرض التوضيحي والتواصل، وإجراءات إنشاء الحساب — وهي حالات نعمل فيها بصفتنا جهة التحكم في البيانات.`,
      },
      {
        type: "p",
        en: `For the documents, matters, and queries your firm processes inside the product ("Customer Content"), Wathiq acts as a data processor on your firm's behalf, under your subscription and data-processing terms. Requests about personal data within Customer Content should be directed to your firm, which is the controller for that data.`,
        ar: `أما المستندات والقضايا والاستفسارات التي يعالجها مكتبك داخل المنتج («محتوى العميل»)، فتعمل وثّق بشأنها بصفتها جهة معالجة بالنيابة عن مكتبك، بموجب اشتراكك وشروط معالجة البيانات. وتُوجَّه الطلبات المتعلقة بالبيانات الشخصية الواردة ضمن محتوى العميل إلى مكتبك بوصفه جهة التحكم في تلك البيانات.`,
      },
    ],
  },
  {
    id: "collect",
    title: { en: "2. Data we collect", ar: "٢. البيانات التي نجمعها" },
    blocks: [
      {
        type: "ul",
        en: [
          <><strong>Information you give us</strong> — when you request a demo or contact us: your name, work email, firm name, role, and the contents of your message.</>,
          <><strong>Account data</strong> — name, email, organisation, and role when an account is created for you.</>,
          <><strong>Work content</strong> — documents, matters, notes, and vault files you upload to the product.</>,
          <><strong>Query text</strong> — the prompts and instructions you submit to AI features.</>,
          <><strong>Audit logs</strong> — records of access to sensitive data, kept to secure the platform.</>,
          <><strong>Device & usage data</strong> — IP address, browser type, and session timestamps, collected automatically.</>,
        ],
        ar: [
          <><strong>المعلومات التي تزوّدنا بها</strong> — عند طلب عرض توضيحي أو التواصل معنا: اسمك وبريدك المهني واسم مكتبك ومسمّاك الوظيفي ومضمون رسالتك.</>,
          <><strong>بيانات الحساب</strong> — الاسم والبريد الإلكتروني والجهة والمسمّى الوظيفي عند إنشاء حساب لك.</>,
          <><strong>محتوى العمل</strong> — المستندات والقضايا والملاحظات وملفات الخزنة التي ترفعها إلى المنتج.</>,
          <><strong>نص الاستفسارات</strong> — الأوامر والتعليمات التي تُرسلها إلى ميزات الذكاء الاصطناعي.</>,
          <><strong>سجلات التدقيق</strong> — سجلات الوصول إلى البيانات الحساسة، تُحفظ لتأمين المنصة.</>,
          <><strong>بيانات الجهاز والاستخدام</strong> — عنوان IP ونوع المتصفّح وأوقات الجلسات، تُجمع تلقائياً.</>,
        ],
      },
    ],
  },
  {
    id: "use",
    title: { en: "3. How we use data", ar: "٣. كيفية استخدامنا للبيانات" },
    blocks: [
      {
        type: "ul",
        en: [
          "To operate the Service and deliver its legal-AI features.",
          "To respond to demo requests and enquiries, and to communicate with you about your account.",
          "To authenticate users and enforce role-based access control (RBAC).",
          "To secure the platform and prevent fraud or misuse.",
          "To comply with our legal and regulatory obligations.",
          "To improve platform reliability and model performance — where this relies on your content beyond what is needed to run the Service, we seek your consent.",
        ],
        ar: [
          "تشغيل الخدمة وتقديم ميزاتها القانونية المدعومة بالذكاء الاصطناعي.",
          "الرد على طلبات العروض التوضيحية والاستفسارات، والتواصل معك بشأن حسابك.",
          "التحقق من هوية المستخدمين وتطبيق التحكم في الوصول المبني على الأدوار.",
          "تأمين المنصة ومنع الاحتيال أو إساءة الاستخدام.",
          "الامتثال لالتزاماتنا النظامية والرقابية.",
          "تحسين موثوقية المنصة وأداء النماذج — وحين يعتمد ذلك على محتواك بما يتجاوز ما يلزم لتشغيل الخدمة، نطلب موافقتك.",
        ],
      },
    ],
  },
  {
    id: "cross-border",
    title: { en: "4. AI usage", ar: "٤. استخدام الذكاء الاصطناعي" },
    blocks: [
      {
        type: "note",
        label: { en: "AI processing notice", ar: "إشعار بشأن معالجة الذكاء الاصطناعي" },
        en: [
          `To provide AI features (document analysis, legal research, and chat), text you submit is processed by third-party AI providers located outside the Kingdom of Saudi Arabia.`,
        ],
        ar: [
          `لتقديم ميزات الذكاء الاصطناعي (تحليل المستندات والبحث القانوني والدردشة)، يُعالَج النص الذي تُدخله لدى مزوّدي نماذج ذكاء اصطناعي خارج المملكة العربية السعودية.`,
        ],
      },
      {
        type: "ul",
        en: [
          "OpenAI — GPT-series models for text generation and analysis.",
          "Anthropic — Claude models for advanced legal reasoning.",
          "Tavily — used only when a query requires a web search.",
        ],
        ar: [
          "OpenAI — نماذج GPT لتوليد النصوص وتحليلها.",
          "Anthropic — نماذج Claude للاستدلال القانوني المتقدّم.",
          "Tavily — تُستخدم فقط عندما يتطلّب الاستفسار بحثاً على الويب.",
        ],
      },
      {
        type: "p",
        en: `The platform itself — and your stored documents and data — is hosted on Google Cloud infrastructure inside the Kingdom of Saudi Arabia (the Dammam region). Before text is sent to the AI providers above, Wathiq applies automated pseudonymisation designed to detect and replace direct personal identifiers — such as names, national IDs, IBANs, and contact details — with coded placeholders, so that the personal data leaving the Kingdom is minimised. This is best-effort and may not catch every identifier (for example, in scanned or image-based documents), and these transfers are made with appropriate contractual and technical safeguards. We contractually require these providers not to use your content to train their models. This processing is necessary to deliver the Service; you can withdraw consent for AI processing on any specific matter from the "My data" page in the product, and we stop AI processing for that matter within 24 hours.`,
        ar: `أما المنصة نفسها — ومستنداتك وبياناتك المخزّنة — فتُستضاف على بنية Google Cloud داخل المملكة العربية السعودية (منطقة الدمّام). وقبل إرسال النص إلى مزوّدي الذكاء الاصطناعي أعلاه، تطبّق وثّق إخفاءً آلياً للهوية (تجهيلاً مستعاراً) يهدف إلى رصد المعرّفات الشخصية المباشرة — كالأسماء وأرقام الهوية الوطنية والآيبان وبيانات التواصل — واستبدالها برموز نائبة، بحيث تُقلَّل البيانات الشخصية التي تغادر المملكة إلى أدنى حد. وتُبذل في ذلك العناية الممكنة، وقد لا يشمل ذلك كل معرّف (مثلاً في المستندات الممسوحة ضوئياً أو الصورية)، وتُجرى عمليات النقل هذه مع تطبيق ضمانات تعاقدية وتقنية مناسبة. ونشترط تعاقدياً على هؤلاء المزوّدين عدم استخدام محتواك لتدريب نماذجهم. وهذه المعالجة ضرورية لتقديم الخدمة؛ ويمكنك سحب الموافقة على معالجة الذكاء الاصطناعي لأي قضية محددة من صفحة «بياناتي» داخل المنتج، فنوقف المعالجة لتلك القضية خلال ٢٤ ساعة.`,
      },
    ],
  },
  {
    id: "sharing",
    title: { en: "5. Sharing & sub-processors", ar: "٥. المشاركة وجهات المعالجة الفرعية" },
    blocks: [
      {
        type: "p",
        en: `We do not sell your personal data. We share it only with service providers who help us run the Service, under contracts that require them to protect it: our cloud host (Google Cloud, Kingdom of Saudi Arabia — Dammam region); the AI providers named above (OpenAI, Anthropic, and Tavily for web search only); and our email-delivery provider (Resend). Transfers to recipients outside the Kingdom are made with appropriate contractual safeguards and data minimisation. We may also disclose data where required by law or a competent authority, or to protect our rights and the safety of users.`,
        ar: `لا نبيع بياناتك الشخصية، ولا نشاركها إلا مع مزوّدي الخدمات الذين يعاوننا في تشغيل الخدمة، بموجب عقود تُلزمهم بحمايتها: مزوّد الاستضافة السحابية (Google Cloud، المملكة العربية السعودية — منطقة الدمّام)؛ ومزوّدو الذكاء الاصطناعي المذكورون أعلاه (OpenAI وAnthropic، وTavily للبحث على الويب فقط)؛ ومزوّد إرسال البريد الإلكتروني (Resend). وتُجرى عمليات النقل إلى جهات خارج المملكة مع تطبيق ضمانات تعاقدية مناسبة وتقليل البيانات. وقد نُفصح عن البيانات أيضاً عند طلب النظام أو جهة مختصة، أو لحماية حقوقنا وسلامة المستخدمين.`,
      },
    ],
  },
  {
    id: "retention",
    title: { en: "6. Data retention", ar: "٦. الاحتفاظ بالبيانات" },
    blocks: [
      {
        type: "table",
        head: { en: ["Data type", "Retention period"], ar: ["نوع البيانات", "فترة الاحتفاظ"] },
        rows: [
          { en: ["Demo / contact enquiries", "Until handled, then up to 24 months"], ar: ["طلبات العروض والتواصل", "حتى معالجة الطلب، ثم حتى ٢٤ شهراً"] },
          { en: ["Account data", "Duration of the account + 30 days after deletion"], ar: ["بيانات الحساب", "طوال مدة الحساب + ٣٠ يوماً بعد الحذف"] },
          { en: ["Matter & document content", "As set by your firm (the data controller) — typically up to ~10 years for professional records"], ar: ["محتوى القضايا والمستندات", "حسبما يحدّده مكتبك (جهة التحكم) — عادةً حتى نحو ١٠ سنوات للسجلات المهنية"] },
          { en: ["Audit logs", "7 years (security & accountability)"], ar: ["سجلات التدقيق", "٧ سنوات (لأغراض الأمن والمساءلة)"] },
          { en: ["Consent records", "5 years from last interaction"], ar: ["سجلات الموافقة", "٥ سنوات من آخر تفاعل"] },
          { en: ["Session data & logs", "90 days"], ar: ["بيانات الجلسات والسجلات", "٩٠ يوماً"] },
        ],
      },
      {
        type: "p",
        en: `When we no longer need personal data, we delete or de-identify (pseudonymise) it. Where that is not immediately possible (for example, data held in secure backups), we isolate it from further processing until deletion is possible.`,
        ar: `عندما تنتفي حاجتنا إلى البيانات الشخصية، نحذفها أو نُزيل صفتها التعريفية (بالتجهيل المستعار). وحيثما يتعذّر ذلك فوراً (كالبيانات المحفوظة في نُسخ احتياطية آمنة)، نعزلها عن أي معالجة أخرى إلى أن يتيسّر حذفها.`,
      },
    ],
  },
  {
    id: "security",
    title: { en: "7. Security", ar: "٧. الأمن" },
    blocks: [
      {
        type: "p",
        en: `We apply technical and organisational measures appropriate to the sensitivity of legal data: encryption in transit and at rest, role-based access control, an append-only, tamper-evident audit log, two-factor authentication (available to every user and required for platform administrators, with mandatory two-factor authentication for firm administrators being rolled out), and data residency inside the Kingdom for the core platform. No system is perfectly secure, but we work continuously to protect your data against loss, misuse, and unauthorised access.`,
        ar: `نطبّق تدابير تقنية وتنظيمية تتناسب مع حساسية البيانات القانونية: التشفير أثناء النقل وفي حالة السكون، والتحكم في الوصول المبني على الأدوار، وسجل تدقيق غير قابل للتعديل ومقاوم للعبث، والتحقق الثنائي (المتاح لكل مستخدم والمطلوب لمسؤولي المنصة، مع العمل على فرضه إلزامياً لمسؤولي المكاتب)، وإقامة البيانات داخل المملكة بالنسبة للمنصة الأساسية. ولا يوجد نظام آمن تماماً، لكننا نعمل باستمرار على حماية بياناتك من الفقد وإساءة الاستخدام والوصول غير المصرَّح به.`,
      },
    ],
  },
  {
    id: "rights",
    title: { en: "8. Your rights under the PDPL", ar: "٨. حقوقك بموجب نظام حماية البيانات" },
    blocks: [
      {
        type: "ul",
        en: [
          <><strong>Access</strong> — request a copy of your personal data.</>,
          <><strong>Rectification</strong> — correct inaccurate or incomplete data.</>,
          <><strong>Erasure</strong> — request deletion of your account, subject to legal-hold retention.</>,
          <><strong>Portability</strong> — receive your data in a machine-readable format.</>,
          <><strong>Withdraw consent</strong> — stop optional processing such as AI, analytics, or marketing.</>,
        ],
        ar: [
          <><strong>الوصول</strong> — طلب نسخة من بياناتك الشخصية.</>,
          <><strong>التصحيح</strong> — تصحيح البيانات غير الدقيقة أو الناقصة.</>,
          <><strong>الحذف</strong> — طلب حذف حسابك، مع مراعاة الاحتفاظ النظامي.</>,
          <><strong>النقل</strong> — الحصول على بياناتك بصيغة قابلة للقراءة آلياً.</>,
          <><strong>سحب الموافقة</strong> — إيقاف المعالجة الاختيارية كالذكاء الاصطناعي أو التحليلات أو التسويق.</>,
        ],
      },
      {
        type: "p",
        en: `Account holders can exercise these rights from the "My data" page inside the product. We respond within 30 days, in line with the PDPL. You also have the right to lodge a complaint with the competent supervisory authority in the Kingdom.`,
        ar: `يمكن لأصحاب الحسابات ممارسة هذه الحقوق من صفحة «بياناتي» داخل المنتج. ونستجيب خلال ٣٠ يوماً اتساقاً مع النظام. ولك أيضاً الحق في تقديم شكوى إلى الجهة الرقابية المختصة في المملكة.`,
      },
    ],
  },
  {
    id: "cookies",
    title: { en: "9. Cookies & website data", ar: "٩. ملفات الارتباط وبيانات الموقع" },
    blocks: [
      {
        type: "p",
        en: `Our marketing website uses only essential and functional storage — for example, remembering your language choice on these legal pages. We do not set advertising cookies on the marketing site. The site loads some resources (such as fonts) from third-party providers, which may receive your IP address as part of delivering them. If we introduce analytics or advertising cookies in future, we will update this policy and request consent where the law requires it.`,
        ar: `يستخدم موقعنا التسويقي تخزيناً ضرورياً ووظيفياً فقط — كتذكّر اختيارك للّغة في هذه الصفحات القانونية. ولا نضع ملفات ارتباط إعلانية على الموقع التسويقي. ويُحمّل الموقع بعض الموارد (كالخطوط) من مزوّدين خارجيين قد يتلقّون عنوان IP الخاص بك ضمن عملية تقديمها. وإذا أضفنا مستقبلاً ملفات ارتباط للتحليلات أو الإعلانات، فسنحدّث هذه السياسة ونطلب الموافقة حيثما يوجب النظام ذلك.`,
      },
    ],
  },
  {
    id: "children",
    title: { en: "10. Children", ar: "١٠. الأطفال" },
    blocks: [
      {
        type: "p",
        en: `The Service is intended for legal professionals and is not directed to anyone under the age of 18. We do not knowingly collect personal data from children.`,
        ar: `الخدمة مخصصة للمختصين القانونيين وليست موجَّهة لمن تقلّ أعمارهم عن ١٨ عاماً. ولا نجمع عن قصد بيانات شخصية للأطفال.`,
      },
    ],
  },
  {
    id: "changes",
    title: { en: "11. Changes to this policy", ar: "١١. تعديل هذه السياسة" },
    blocks: [
      {
        type: "p",
        en: `We may update this Privacy Policy from time to time. We will post the updated version here and, where a change is significant, take additional steps to notify you.`,
        ar: `قد نُحدّث سياسة الخصوصية هذه من وقت لآخر. وسننشر النسخة المحدَّثة هنا، وعند أهمية التغيير نتخذ خطوات إضافية لإشعارك.`,
      },
    ],
  },
  {
    id: "contact",
    title: { en: "12. Contact us", ar: "١٢. التواصل معنا" },
    blocks: [
      {
        type: "p",
        en: <>For any privacy enquiry, or to exercise your rights, contact our privacy team at <a href="mailto:info@wathiq.ai">info@wathiq.ai</a>. If we do not resolve your complaint within seven business days, or you are not satisfied with the outcome, you may escalate it to the National Data Management Office at <a href="mailto:pr@ndmo.gov.sa">pr@ndmo.gov.sa</a>.</>,
        ar: <>لأي استفسار يتعلق بالخصوصية أو لممارسة حقوقك، تواصل مع فريق الخصوصية على <a href="mailto:info@wathiq.ai">info@wathiq.ai</a>. وإذا لم تُعالَج شكواك خلال سبعة أيام عمل، أو لم تكن راضياً عن نتيجتها، فيمكنك التصعيد إلى مكتب إدارة البيانات الوطنية عبر <a href="mailto:pr@ndmo.gov.sa">pr@ndmo.gov.sa</a>.</>,
      },
      {
        type: "p",
        en: <>The Service is operated by Fares Ibrahim Alghamdi & Abdulrahman Yasser Osailan Company (a limited liability company incorporated in the Kingdom of Saudi Arabia, unified national number 7050363576), headquartered in the Kingdom of Saudi Arabia.</>,
        ar: <>تُشغَّل الخدمة بواسطة شركة فارس إبراهيم الغامدي وعبدالرحمن ياسر عسيلان (شركة ذات مسؤولية محدودة مؤسسة في المملكة العربية السعودية، الرقم الوطني الموحد 7050363576)، ومقرها المملكة العربية السعودية.</>,
      },
    ],
  },
];

/* ============================================================
   PAGE COMPONENTS
   ============================================================ */

function TermsPage() {
  return (
    <LegalPage
      eyebrow={{ en: "Legal", ar: "قانوني" }}
      title={{ en: "Terms & Conditions", ar: "الشروط والأحكام" }}
      updated={{ en: "Last updated: 25 June 2026", ar: "آخر تحديث: ٢٥ يونيو ٢٠٢٦" }}
      lede={{
        en: "These Terms set out the agreement between Wathiq and the firms and legal professionals who use our platform. Please read them alongside our Privacy Policy.",
        ar: "تبيّن هذه الشروط الاتفاق بين وثّق والمكاتب والمختصين القانونيين الذين يستخدمون منصّتنا. ويُرجى قراءتها إلى جانب سياسة الخصوصية.",
      }}
      sections={TERMS_SECTIONS}
    />
  );
}

function PrivacyPage() {
  return (
    <LegalPage
      eyebrow={{ en: "Legal", ar: "قانوني" }}
      title={{ en: "Privacy Policy", ar: "سياسة الخصوصية" }}
      updated={{ en: "Last updated: 25 June 2026", ar: "آخر تحديث: ٢٥ يونيو ٢٠٢٦" }}
      lede={{
        en: "Wathiq is built for the most sensitive legal work. This policy explains what personal data we handle, how we protect it, and the choices you have — under the Saudi Personal Data Protection Law.",
        ar: "صُممت وثّق لأكثر الأعمال القانونية حساسية. وتوضّح هذه السياسة البيانات الشخصية التي نتعامل معها، وكيف نحميها، والخيارات المتاحة لك — وفق نظام حماية البيانات الشخصية السعودي.",
      }}
      sections={PRIVACY_SECTIONS}
    />
  );
}

Object.assign(window, { TermsPage, PrivacyPage });
