"use client"

import Link from "next/link"
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"
import { ScrollArea } from "@/components/ui/scroll-area"

export type LegalPolicyType = "privacy" | "terms" | "cookie"

export function PrivacyPolicyContent() {
  return (
    <div>
      <h1 className="text-2xl font-bold mb-6">Privacy Policy</h1>

      <p className="mb-4">Tech Excel Innovations built the Affiliate+ app as a free Android application. This Service is provided by Tech Excel Innovations at no cost and is intended for use as is.</p>

      <p className="mb-4">This page is used to inform visitors regarding our policies with the collection, use, and disclosure of Personal Information if anyone decided to use our Service.</p>

      <p className="mb-4">If you choose to use our Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that we collect is used for providing and improving the Service. We will not use or share your information with anyone except as described in this Privacy Policy.</p>

      <p className="mb-4">The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which are accessible within Affiliate+ unless otherwise defined in this Privacy Policy.</p>

      <h2 className="text-xl font-semibold mt-8 mb-3">Information Collection and Use</h2>
      <p className="mb-4">For a better experience with the Affiliate+ Android app, we may require you to provide certain personally identifiable information, including but not limited to Name, Phone, Email Address, Location, and IP Address. The information we request will be retained by us and used as described in this Privacy Policy.</p>
      <p className="mb-4">The app does use third-party services that may collect information used to identify you.</p>

      <h3 className="text-lg font-semibold mt-6 mb-2">Third-Party Services</h3>
      <p className="mb-3">Link to the privacy policy of third-party service providers used by the Android app:</p>
      <ul className="list-disc pl-6 space-y-1 mb-4">
        <li>Google Play Services</li>
        <li>AdMob</li>
        <li>Google Analytics for Firebase</li>
        <li>Firebase Crashlytics</li>
        <li>One Signal</li>
      </ul>

      <h2 className="text-xl font-semibold mt-8 mb-3">Log Data</h2>
      <p className="mb-4">We want to inform you that whenever you use our Service, in a case of an error in the Android app we collect data and information (through third-party products) on your device called Log Data. This Log Data may include information such as your device Internet Protocol ("IP") address, device name, operating system version, the configuration of the app when utilizing our Service, the time and date of your use of the Service, and other statistics.</p>

      <h2 className="text-xl font-semibold mt-8 mb-3">Cookies</h2>
      <p className="mb-4">Cookies are files with a small amount of data that are commonly used as anonymous unique identifiers. These are sent to your browser from the websites that you visit and are stored on your device's internal memory.</p>
      <p className="mb-4">This Service does not use these "cookies" explicitly. However, the app may use third-party code and libraries that use "cookies" to collect information and improve their services. You have the option to either accept or refuse these cookies and know when a cookie is being sent to your device. If you choose to refuse our cookies, you may not be able to use some portions of this Service.</p>

      <h2 className="text-xl font-semibold mt-8 mb-3">Service Providers</h2>
      <p className="mb-4">We may employ third-party companies and individuals due to the following reasons:</p>
      <ul className="list-disc pl-6 space-y-1 mb-4">
        <li>To facilitate our Service;</li>
        <li>To provide the Service on our behalf;</li>
        <li>To perform Service-related services; or</li>
        <li>To assist us in analyzing how our Service is used.</li>
      </ul>
      <p className="mb-4">We want to inform users of this Service that these third parties have access to their Personal Information. The reason is to perform the tasks assigned to them on our behalf. However, they are obligated not to disclose or use the information for any other purpose.</p>

      <h2 className="text-xl font-semibold mt-8 mb-3">Security</h2>
      <p className="mb-4">We value your trust in providing us your Personal Information, thus we are striving to use commercially acceptable means of protecting it. But remember that no method of transmission over the internet, or method of electronic storage is 100% secure and reliable, and we cannot guarantee its absolute security.</p>

      <h2 className="text-xl font-semibold mt-8 mb-3">Links to Other Sites</h2>
      <p className="mb-4">This Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by us. Therefore, we strongly advise you to review the Privacy Policy of these websites. We have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.</p>

      <h2 className="text-xl font-semibold mt-8 mb-3">Children's Privacy</h2>
      <p className="mb-4">These Services do not address anyone under the age of 13. We do not knowingly collect personally identifiable information from children under 13 years of age. In the case we discover that a child under 13 has provided us with personal information, we immediately delete this from our servers. If you are a parent or guardian and you are aware that your child has provided us with personal information, please contact us so that we will be able to do the necessary actions.</p>

      <h2 className="text-xl font-semibold mt-8 mb-3">Changes to This Privacy Policy</h2>
      <p className="mb-4">We may update our Privacy Policy from time to time. Thus, you are advised to review this page periodically for any changes. We will notify you of any changes by posting the new Privacy Policy on this page.</p>
      <p className="mb-4">This policy is effective as of 2022-01-02</p>

      <h2 className="text-xl font-semibold mt-8 mb-3">Your Data Protection Rights</h2>
      <p className="mb-3">We respect your data protection rights. These rights include:</p>
      <ul className="list-disc pl-6 space-y-1 mb-4">
        <li>The right to access your personal data.</li>
        <li>The right to correction or deletion of inaccurate data.</li>
        <li>The right to data portability.</li>
        <li>The right to withdraw consent at any time.</li>
        <li>The right to lodge a complaint with the relevant data protection authority.</li>
      </ul>
      <p className="mb-3">The lawful bases for processing include consent, performance of a contract, compliance with a legal obligation, and our legitimate interests in preventing fraud, improving the Service, and keeping users safe.</p>
      <p className="mb-4">We retain personal data only as long as necessary for the purposes described and apply appropriate technical and organizational security measures to protect it against unauthorized access, alteration, and disclosure.</p>

      <h2 className="text-xl font-semibold mt-8 mb-3">Contact Us</h2>
      <p className="mb-2">If you have any questions or suggestions about our Privacy Policy, do not hesitate to contact us at <a href="mailto:hello@techex.com.ng" className="text-blue-600 underline">hello@techex.com.ng</a>.</p>
    </div>
  )
}

export function TermsContent() {
  return (
    <div>
      <h1 className="text-2xl font-bold mb-6">Terms of Service</h1>

      <p className="mb-4 text-sm text-gray-600">Last Updated: January 1, 2024</p>

      <p className="mb-4">
        Welcome to Affiliate+. These Terms of Service ("Terms") govern your access to and use of the Affiliate+ website, mobile application, and related services (collectively, the "Service"). By accessing or using our Service, you agree to be bound by these Terms and our Privacy Policy.
      </p>

      <h2 className="text-xl font-semibold mt-8 mb-3">1. Acceptance of Terms</h2>
      <p className="mb-4">
        By registering for, accessing, browsing, or using the Service, you acknowledge that you have read, understood, and agree to be bound by these Terms. If you do not agree to these Terms, you may not access or use the Service. We reserve the right to update or modify these Terms at any time without prior notice, and such changes will be effective immediately upon posting.
      </p>

      <h2 className="text-xl font-semibold mt-8 mb-3">2. User Accounts and Responsibilities</h2>
      <p className="mb-4">
        To use certain features of the Service, you must register for an account. You agree to provide accurate, current, and complete information during the registration process and to update such information to keep it accurate, current, and complete. You are responsible for safeguarding your password and for all activities that occur under your account. You agree to notify us immediately of any unauthorized use of your account.
      </p>

      <h2 className="text-xl font-semibold mt-8 mb-3">3. Prohibited Conduct</h2>
      <p className="mb-4">
        You agree not to engage in any of the following prohibited activities:
      </p>
      <ul className="list-disc pl-6 space-y-2 mb-4">
        <li>Using the Service for any illegal purpose or in violation of any local, state, national, or international law.</li>
        <li>Violating or encouraging others to violate third-party rights, including intellectual property rights.</li>
        <li>Posting, uploading, or distributing any content that is unlawful, defamatory, harassing, abusive, fraudulent, obscene, or otherwise objectionable.</li>
        <li>Interfering with security-related features of the Service, including by disabling or circumventing features that prevent or limit use or copying of any content.</li>
        <li>Attempting to access or search the Service or content or download content from the Service through the use of any engine, software, tool, agent, device, or mechanism other than the software and/or search agents provided by us or other generally available third-party web browsers.</li>
      </ul>

      <h2 className="text-xl font-semibold mt-8 mb-3">4. Intellectual Property</h2>
      <p className="mb-4">
        The Service and its original content, features, and functionality are and will remain the exclusive property of Affiliate+ and its licensors. The Service is protected by copyright, trademark, and other laws of both the Federal Republic of Nigeria and foreign countries. Our trademarks and trade dress may not be used in connection with any product or service without the prior written consent of Affiliate+.
      </p>

      <h2 className="text-xl font-semibold mt-8 mb-3">5. Termination</h2>
      <p className="mb-4">
        We may terminate or suspend your account and bar access to the Service immediately, without prior notice or liability, under our sole discretion, for any reason whatsoever and without limitation, including but not limited to a breach of the Terms. Upon termination, your right to use the Service will immediately cease.
      </p>

      <h2 className="text-xl font-semibold mt-8 mb-3">6. Limitation of Liability</h2>
      <p className="mb-4">
        In no event shall Affiliate+, nor its directors, employees, partners, agents, suppliers, or affiliates, be liable for any indirect, incidental, special, consequential or punitive damages, including without limitation, loss of profits, data, use, goodwill, or other intangible losses, resulting from (i) your access to or use of or inability to access or use the Service; (ii) any conduct or content of any third party on the Service; (iii) any content obtained from the Service; and (iv) unauthorized access, use or alteration of your transmissions or content, whether based on warranty, contract, tort (including negligence) or any other legal theory, whether or not we have been informed of the possibility of such damage.
      </p>

      <h2 className="text-xl font-semibold mt-8 mb-3">7. Governing Law</h2>
      <p className="mb-4">
        These Terms shall be governed and construed in accordance with the laws of Nigeria, without regard to its conflict of law provisions. Our failure to enforce any right or provision of these Terms will not be considered a waiver of those rights.
      </p>

      <h2 className="text-xl font-semibold mt-8 mb-3">8. Classified Ads & Data Protection</h2>
      <p className="mb-3">
        Affiliate+ operates as a classified ads venue that connects buyers and sellers. Listings are provided by third-party users, and Affiliate+ is not a party to any transaction between users.
      </p>
      <p className="mb-3">
        Contacting a seller is subject to our safety and anti-fraud policies. Fraudulent, misleading, or scam activity may be reported to law enforcement and may result in account termination, disclosure of your identity, and criminal prosecution.
      </p>
      <p className="mb-4">
        We process personal data responsibly and in line with applicable data protection laws. You have the right to access, correct, delete, and port your personal data, and to withdraw consent at any time. See our Privacy Policy and Cookie Policy for details.
      </p>

      <h2 className="text-xl font-semibold mt-8 mb-3">9. Contact Us</h2>
      <p className="mb-2">
        If you have any questions about these Terms, please contact us at <a href="mailto:hello@techex.com.ng" className="text-blue-600 underline">hello@techex.com.ng</a>.
      </p>
    </div>
  )
}

export function CookiePolicyContent() {
  return (
    <div>
      <h1 className="text-2xl font-bold mb-2">Cookie Policy</h1>
      <p className="text-sm text-gray-500 mb-6">Last updated: 5 November 2026</p>

      <div className="space-y-6 text-gray-700">
        <section>
          <h2 className="text-lg font-semibold text-gray-900">1. What are cookies?</h2>
          <p>
            Cookies are small text files stored on your device when you visit a website. They help
            the site remember your preferences, keep you signed in, and understand how the service
            is used. We also use similar technologies such as local storage and pixels.
          </p>
        </section>

        <section>
          <h2 className="text-lg font-semibold text-gray-900">2. How we use cookies</h2>
          <ul className="list-disc pl-5 space-y-1">
            <li><strong>Essential cookies</strong>, required for authentication, security, and core functionality.</li>
            <li><strong>Preference cookies</strong>, remember your language, currency, and consent choices.</li>
            <li><strong>Analytics cookies</strong>, help us measure traffic and improve the platform.</li>
            <li><strong>Advertising cookies</strong>, used by third-party partners to show relevant ads.</li>
          </ul>
        </section>

        <section>
          <h2 className="text-lg font-semibold text-gray-900">3. Third-party cookies</h2>
          <p>
            We use trusted third-party services (such as Google Analytics, Meta Pixel, and
            Cloudflare Turnstile) that may set their own cookies. These providers process data
            under their own privacy policies.
          </p>
        </section>

        <section>
          <h2 className="text-lg font-semibold text-gray-900">4. Managing your preferences</h2>
          <p>
            You can control or delete cookies through your browser settings. Disabling essential
            cookies may prevent parts of the platform from working correctly. You may withdraw
            consent at any time by clearing your browser storage.
          </p>
        </section>

        <section>
          <h2 className="text-lg font-semibold text-gray-900">5. Data protection</h2>
          <p>
            We process personal data responsibly and in line with applicable data protection laws.
            For more information on how we collect, use, and protect your data, please read our{" "}
            <Link href="/privacy-policy" className="text-purple-600 underline">
              Privacy Policy
            </Link>
            .
          </p>
        </section>

        <section>
          <h2 className="text-lg font-semibold text-gray-900">6. Contact</h2>
          <p>
            For questions about this Cookie Policy, contact us via the{" "}
            <Link href="/contact" className="text-purple-600 underline">
              Contact page
            </Link>
            .
          </p>
        </section>
      </div>
    </div>
  )
}

interface LegalPolicyModalProps {
  open: boolean
  onOpenChange: (open: boolean) => void
  type: LegalPolicyType
}

export function LegalPolicyModal({ open, onOpenChange, type }: LegalPolicyModalProps) {
  const config = {
    privacy: { title: "Privacy Policy", Content: PrivacyPolicyContent },
    terms: { title: "Terms of Service", Content: TermsContent },
    cookie: { title: "Cookie Policy", Content: CookiePolicyContent },
  }[type]

  const Content = config.Content

  return (
    <Dialog open={open} onOpenChange={onOpenChange}>
      <DialogContent className="max-w-2xl max-h-[85vh] p-0 gap-0 overflow-hidden z-[120]">
        <div className="flex max-h-[85vh] flex-col">
          <DialogHeader className="px-6 pt-6 pb-4 border-b border-gray-100 shrink-0">
            <DialogTitle className="text-xl font-bold">{config.title}</DialogTitle>
          </DialogHeader>
          <ScrollArea className="flex-1 min-h-0 px-6 py-5">
            <Content />
          </ScrollArea>
        </div>
      </DialogContent>
    </Dialog>
  )
}