import { Head, usePage } from '@inertiajs/react';

import { MarketingFooter } from '@/Components/marketing/MarketingFooter';
import { MarketingNav } from '@/Components/marketing/MarketingNav';
import { type PageProps } from '@/types';

interface DpaProps {
  canLogin: boolean;
  canRegister: boolean;
}

type DpaComponent = ((props: DpaProps) => JSX.Element) & {
  disableGlobalUi?: boolean;
};

const Dpa: DpaComponent = ({ canLogin, canRegister }) => {
  const appName = import.meta.env.VITE_APP_NAME || 'RankWiz';
  const { app_url } = usePage<PageProps>().props;
  const lastUpdated = 'March 18, 2026';

  return (
    <>
      <Head title="Data Processing Agreement">
        <link rel="canonical" href={`${app_url}/dpa`} />
        <meta
          name="description"
          content={`Data Processing Agreement for ${appName}. Standard contractual terms for enterprise customers under GDPR.`}
        />
        <meta property="og:title" content={`Data Processing Agreement — ${appName}`} />
        <meta
          property="og:description"
          content={`GDPR-compliant Data Processing Agreement for ${appName} enterprise customers.`}
        />
        <meta name="robots" content="noindex, follow" />
        <meta property="og:type" content="website" />
        <meta property="og:url" content={`${app_url}/dpa`} />
        <meta property="og:image" content={`${app_url}/og-image.png`} />
        <meta property="og:image:alt" content={`${appName} — Data Processing Agreement`} />
        <meta name="twitter:card" content="summary_large_image" />
        <meta name="twitter:title" content={`Data Processing Agreement — ${appName}`} />
        <meta
          name="twitter:description"
          content={`GDPR-compliant DPA for ${appName} enterprise customers.`}
        />
      </Head>

      <div className="min-h-screen bg-gradient-to-b from-background to-muted/30">
        <MarketingNav canLogin={canLogin} canRegister={canRegister} />

        <main id="main-content">
          <section className="container max-w-3xl py-16">
            <h1 className="text-4xl font-bold tracking-tight">Data Processing Agreement</h1>
            <p className="mt-2 text-sm text-muted-foreground">Last updated: {lastUpdated}</p>

            <div className="mt-10 space-y-8 text-muted-foreground leading-relaxed">
              <div>
                <p className="mt-3">
                  This Data Processing Agreement (&quot;DPA&quot;) forms part of the Terms of
                  Service between {appName} (&quot;Processor&quot;) and the customer
                  (&quot;Controller&quot;) who has entered into a subscription agreement for the
                  Service.
                </p>
              </div>

              <div>
                <h2 className="text-xl font-semibold text-foreground">1. Definitions</h2>
                <ul className="mt-3 list-disc space-y-1 pl-6">
                  <li>
                    <strong>&quot;Personal Data&quot;</strong> means any information relating to an
                    identified or identifiable natural person as defined in GDPR Article 4(1).
                  </li>
                  <li>
                    <strong>&quot;Processing&quot;</strong> means any operation performed on Personal
                    Data, as defined in GDPR Article 4(2).
                  </li>
                  <li>
                    <strong>&quot;Sub-processor&quot;</strong> means any third party engaged by the
                    Processor to process Personal Data on behalf of the Controller.
                  </li>
                </ul>
              </div>

              <div>
                <h2 className="text-xl font-semibold text-foreground">
                  2. Scope and Purpose of Processing
                </h2>
                <p className="mt-3">
                  The Processor processes Personal Data solely for the purpose of providing the
                  Service as described in the Terms of Service. Processing activities include:
                </p>
                <ul className="mt-2 list-disc space-y-1 pl-6">
                  <li>Account management (name, email address)</li>
                  <li>Google Search Console data synchronisation and analysis</li>
                  <li>WordPress content inventory and publishing</li>
                  <li>AI-assisted content generation (using Controller-provided API keys)</li>
                  <li>SEO analysis, recommendations, and reporting</li>
                  <li>Audit logging for security and compliance</li>
                </ul>
              </div>

              <div>
                <h2 className="text-xl font-semibold text-foreground">
                  3. Obligations of the Processor
                </h2>
                <p className="mt-3">The Processor shall:</p>
                <ul className="mt-2 list-disc space-y-1 pl-6">
                  <li>
                    Process Personal Data only on documented instructions from the Controller (GDPR
                    Art. 28(3)(a))
                  </li>
                  <li>
                    Ensure that persons authorised to process Personal Data are bound by
                    confidentiality obligations (GDPR Art. 28(3)(b))
                  </li>
                  <li>
                    Implement appropriate technical and organisational security measures (GDPR Art.
                    32), including encryption at rest (AES-256) for sensitive data, HTTPS with HSTS,
                    and rate limiting
                  </li>
                  <li>
                    Not engage another processor without prior written authorisation of the
                    Controller (GDPR Art. 28(2))
                  </li>
                  <li>
                    Assist the Controller in responding to data subject requests (GDPR Art. 28(3)(e))
                  </li>
                  <li>
                    Notify the Controller without undue delay upon becoming aware of a Personal Data
                    breach (GDPR Art. 33)
                  </li>
                  <li>
                    Delete or return all Personal Data upon termination of the Service, unless
                    retention is required by law (GDPR Art. 28(3)(g))
                  </li>
                  <li>
                    Make available all information necessary to demonstrate compliance and allow for
                    audits (GDPR Art. 28(3)(h))
                  </li>
                </ul>
              </div>

              <div>
                <h2 className="text-xl font-semibold text-foreground">4. Sub-processors</h2>
                <p className="mt-3">
                  The Controller authorises the use of the sub-processors listed on our{' '}
                  <a href="/legal/sub-processors" className="underline hover:text-foreground">
                    Sub-Processors page
                  </a>
                  . The Processor will notify the Controller of any intended changes to
                  sub-processors, giving the Controller the opportunity to object.
                </p>
              </div>

              <div>
                <h2 className="text-xl font-semibold text-foreground">
                  5. International Data Transfers
                </h2>
                <p className="mt-3">
                  Where Personal Data is transferred outside the EEA, the Processor ensures
                  appropriate safeguards are in place, including Standard Contractual Clauses (SCCs)
                  as approved by the European Commission, or reliance on the EU-US Data Privacy
                  Framework where applicable. Transfer details are documented in our{' '}
                  <a href="/privacy" className="underline hover:text-foreground">
                    Privacy Policy
                  </a>
                  .
                </p>
              </div>

              <div>
                <h2 className="text-xl font-semibold text-foreground">6. Data Retention</h2>
                <p className="mt-3">
                  The Processor retains Personal Data in accordance with the retention schedule
                  published in the Privacy Policy. Upon account deletion, all Personal Data is
                  permanently removed, with audit logs anonymised (PII stripped) as permitted under
                  GDPR for compliance purposes.
                </p>
              </div>

              <div>
                <h2 className="text-xl font-semibold text-foreground">7. Security Measures</h2>
                <p className="mt-3">
                  The Processor implements the following technical and organisational measures:
                </p>
                <ul className="mt-2 list-disc space-y-1 pl-6">
                  <li>Encryption at rest (AES-256) for API keys, OAuth tokens, and HMAC secrets</li>
                  <li>HTTPS with HSTS enforcement for all connections</li>
                  <li>Secure, HTTP-only, SameSite session cookies</li>
                  <li>Content Security Policy headers</li>
                  <li>Rate limiting on authentication and API endpoints</li>
                  <li>Structured audit logging with PII sanitisation</li>
                  <li>Automated data retention enforcement via scheduled jobs</li>
                </ul>
              </div>

              <div>
                <h2 className="text-xl font-semibold text-foreground">8. Breach Notification</h2>
                <p className="mt-3">
                  In the event of a Personal Data breach, the Processor will notify the Controller
                  without undue delay and no later than 72 hours after becoming aware of the breach,
                  in accordance with GDPR Article 33. The notification will include the nature of
                  the breach, categories and approximate number of data subjects affected, likely
                  consequences, and measures taken to address the breach.
                </p>
              </div>

              <div>
                <h2 className="text-xl font-semibold text-foreground">9. Audit Rights</h2>
                <p className="mt-3">
                  The Controller may audit the Processor&apos;s compliance with this DPA once per
                  calendar year, with 30 days prior written notice. The Processor will cooperate
                  with reasonable audit requests and provide access to relevant documentation and
                  systems.
                </p>
              </div>

              <div>
                <h2 className="text-xl font-semibold text-foreground">
                  10. Term and Termination
                </h2>
                <p className="mt-3">
                  This DPA remains in effect for the duration of the Service agreement. Upon
                  termination, the Processor will delete all Personal Data within 30 days, unless
                  retention is required by applicable law.
                </p>
              </div>

              <div>
                <h2 className="text-xl font-semibold text-foreground">11. Governing Law</h2>
                <p className="mt-3">
                  This DPA is governed by the laws applicable to the Terms of Service. For data
                  protection matters, the provisions of the GDPR take precedence where there is a
                  conflict.
                </p>
              </div>

              <div>
                <h2 className="text-xl font-semibold text-foreground">12. Contact</h2>
                <p className="mt-3">
                  To request a signed copy of this DPA or discuss data processing terms, please
                  contact our Data Protection Officer at{' '}
                  <a
                    href={`mailto:dpo@${new URL(app_url).hostname}`}
                    className="underline hover:text-foreground"
                  >
                    dpo@{new URL(app_url).hostname}
                  </a>
                  .
                </p>
              </div>
            </div>
          </section>
        </main>

        <MarketingFooter />
      </div>
    </>
  );
};

Dpa.disableGlobalUi = true;

export default Dpa;
