import React from 'react';
import { useTranslation } from 'react-i18next';
import { FileText, Calendar, AlertTriangle } from 'lucide-react';
import { Card } from '../../components/ui';

export const TermsOfServicePage: React.FC = () => {
  const { t } = useTranslation();

  const lastUpdated = '2025-10-15';

  return (
    <div className="min-h-screen bg-gray-50 dark:bg-gray-900 py-12 px-4">
      <div className="max-w-4xl mx-auto">
        <div className="text-center mb-8">
          <div className="flex justify-center mb-4">
            <FileText className="w-16 h-16 text-primary-600" />
          </div>
          <h1 className="text-4xl font-bold text-gray-900 dark:text-white mb-2">
            {t('legal:terms.title', 'Terms of Service')}
          </h1>
          <div className="flex items-center justify-center gap-2 text-sm text-gray-600 dark:text-gray-400">
            <Calendar className="w-4 h-4" />
            <span>
              {t('legal:terms.last_updated', 'Last updated')}: {lastUpdated}
            </span>
          </div>
        </div>

        <Card className="p-8 prose prose-gray dark:prose-invert max-w-none">
          <section className="mb-8">
            <h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
              1. {t('legal:terms.section_1_title', 'Agreement to Terms')}
            </h2>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              By accessing or using {t('common:app.name', 'BakeWise')} ("the Platform", "our Service"), you agree to be
              bound by these Terms of Service ("Terms"). If you do not agree to these Terms, do not
              use the Platform.
            </p>
            <p className="text-gray-700 dark:text-gray-300">
              These Terms constitute a legally binding agreement between you ("User", "you", "your")
              and {t('common:app.name', 'BakeWise')} regarding your use of the Platform.
            </p>
          </section>

          <section className="mb-8">
            <h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
              2. {t('legal:terms.section_2_title', 'Description of Service')}
            </h2>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              {t('common:app.name', 'BakeWise')} provides a comprehensive bakery management platform that includes:
            </p>
            <ul className="list-disc pl-6 mb-4 text-gray-700 dark:text-gray-300 space-y-1">
              <li>Inventory management and tracking</li>
              <li>Production planning and scheduling</li>
              <li>Sales forecasting and analytics</li>
              <li>Customer and order management</li>
              <li>Recipe management and costing</li>
              <li>Supplier and procurement management</li>
              <li>Point of sale integration</li>
              <li>AI-powered insights and recommendations</li>
            </ul>
            <p className="text-gray-700 dark:text-gray-300">
              We reserve the right to modify, suspend, or discontinue any part of the Service at any
              time with or without notice.
            </p>
          </section>

          <section className="mb-8">
            <h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
              3. {t('legal:terms.section_3_title', 'User Accounts')}
            </h2>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              3.1 Account Registration
            </h3>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              To use the Platform, you must:
            </p>
            <ul className="list-disc pl-6 mb-4 text-gray-700 dark:text-gray-300 space-y-1">
              <li>Be at least 16 years of age</li>
              <li>Provide accurate, current, and complete information</li>
              <li>Maintain and promptly update your account information</li>
              <li>Maintain the security of your password</li>
              <li>Accept responsibility for all activities under your account</li>
            </ul>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              3.2 Account Security
            </h3>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              You are responsible for:
            </p>
            <ul className="list-disc pl-6 mb-4 text-gray-700 dark:text-gray-300 space-y-1">
              <li>Safeguarding your password and account credentials</li>
              <li>Notifying us immediately of any unauthorized access</li>
              <li>Ensuring that you log out from your account at the end of each session</li>
            </ul>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              3.3 Account Termination
            </h3>
            <p className="text-gray-700 dark:text-gray-300">
              We reserve the right to suspend or terminate your account if you violate these Terms or
              engage in fraudulent, abusive, or illegal activity.
            </p>
          </section>

          <section className="mb-8">
            <h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
              4. {t('legal:terms.section_4_title', 'Subscription and Payment')}
            </h2>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              4.1 Subscription Plans
            </h3>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              The Platform offers various subscription plans with different features and pricing. You
              can view current plans and pricing on our website.
            </p>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              4.2 Payment Terms
            </h3>
            <ul className="list-disc pl-6 mb-4 text-gray-700 dark:text-gray-300 space-y-1">
              <li>Subscription fees are billed in advance on a monthly or annual basis</li>
              <li>All fees are non-refundable except as required by law</li>
              <li>You authorize us to charge your payment method for all fees</li>
              <li>Prices may change with 30 days' notice</li>
            </ul>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              4.3 Free Trial
            </h3>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              We may offer a free trial period. At the end of the trial, your subscription will
              automatically convert to a paid plan unless you cancel before the trial ends.
            </p>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              4.4 Cancellation
            </h3>
            <p className="text-gray-700 dark:text-gray-300">
              You may cancel your subscription at any time from your account settings. Cancellation
              takes effect at the end of the current billing period.
            </p>
          </section>

          <section className="mb-8">
            <h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
              5. {t('legal:terms.section_5_title', 'User Conduct and Prohibited Activities')}
            </h2>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              You agree not to:
            </p>
            <ul className="list-disc pl-6 mb-4 text-gray-700 dark:text-gray-300 space-y-2">
              <li>Violate any applicable laws or regulations</li>
              <li>Infringe on intellectual property rights of others</li>
              <li>Upload viruses, malware, or other malicious code</li>
              <li>Attempt to gain unauthorized access to the Platform or related systems</li>
              <li>Interfere with or disrupt the Platform's operation</li>
              <li>Use the Platform for any illegal or unauthorized purpose</li>
              <li>Impersonate any person or entity</li>
              <li>Collect or harvest user data without permission</li>
              <li>Reverse engineer, decompile, or disassemble the Platform</li>
              <li>Use automated systems (bots, scrapers) without authorization</li>
              <li>Resell or redistribute the Service without permission</li>
            </ul>
          </section>

          <section className="mb-8">
            <h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
              6. {t('legal:terms.section_6_title', 'Intellectual Property')}
            </h2>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              6.1 Platform Ownership
            </h3>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              The Platform and all content, features, and functionality are owned by {t('common:app.name', 'BakeWise')} and
              are protected by international copyright, trademark, and other intellectual property laws.
            </p>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              6.2 User Content
            </h3>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              You retain all rights to the data and content you upload to the Platform ("User Content").
              By uploading User Content, you grant us a limited license to:
            </p>
            <ul className="list-disc pl-6 mb-4 text-gray-700 dark:text-gray-300 space-y-1">
              <li>Store, process, and display your User Content to provide the Service</li>
              <li>Create derivative works for analytics and AI features (anonymized)</li>
              <li>Make backups of your data for disaster recovery</li>
            </ul>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              6.3 Trademarks
            </h3>
            <p className="text-gray-700 dark:text-gray-300">
              "{t('common:app.name', 'BakeWise')}" and our logo are trademarks. You may not use our trademarks without
              prior written consent.
            </p>
          </section>

          <section className="mb-8">
            <h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
              7. {t('legal:terms.section_7_title', 'Data Privacy and Protection')}
            </h2>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              Your use of the Platform is also governed by our{' '}
              <a href="/privacy" className="text-primary-600 hover:text-primary-700 underline">
                Privacy Policy
              </a>
              , which is incorporated into these Terms by reference.
            </p>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              We comply with the General Data Protection Regulation (GDPR) and other applicable data
              protection laws. Key points:
            </p>
            <ul className="list-disc pl-6 mb-4 text-gray-700 dark:text-gray-300 space-y-1">
              <li>We are the data controller for your account data</li>
              <li>You are the data controller for customer data you input</li>
              <li>We act as a data processor for your customer data</li>
              <li>We have Data Processing Agreements with all sub-processors</li>
              <li>Data is stored in EU data centers</li>
            </ul>
          </section>

          <section className="mb-8">
            <h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
              8. {t('legal:terms.section_8_title', 'Service Availability and Support')}
            </h2>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              8.1 Availability
            </h3>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              We strive to maintain 99.9% uptime but do not guarantee uninterrupted access. The
              Platform may be unavailable during:
            </p>
            <ul className="list-disc pl-6 mb-4 text-gray-700 dark:text-gray-300 space-y-1">
              <li>Scheduled maintenance (with advance notice)</li>
              <li>Emergency maintenance</li>
              <li>Force majeure events</li>
              <li>Third-party service failures</li>
            </ul>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              8.2 Customer Support
            </h3>
            <p className="text-gray-700 dark:text-gray-300">
              Support is provided based on your subscription plan. Response times and support channels
              vary by plan tier.
            </p>
          </section>

          <section className="mb-8">
            <h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
              9. {t('legal:terms.section_9_title', 'Disclaimers and Limitations of Liability')}
            </h2>

            <div className="bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg p-4 mb-4">
              <div className="flex items-start gap-3">
                <AlertTriangle className="w-5 h-5 text-amber-600 mt-0.5 flex-shrink-0" />
                <div className="text-sm text-amber-900 dark:text-amber-100">
                  <strong>IMPORTANT LEGAL NOTICE</strong>
                </div>
              </div>
            </div>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              9.1 "AS IS" Disclaimer
            </h3>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              THE PLATFORM IS PROVIDED "AS IS" AND "AS AVAILABLE" WITHOUT WARRANTIES OF ANY KIND,
              EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS
              FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
            </p>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              9.2 Limitation of Liability
            </h3>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              TO THE MAXIMUM EXTENT PERMITTED BY LAW, PANADERÍA IA SHALL NOT BE LIABLE FOR:
            </p>
            <ul className="list-disc pl-6 mb-4 text-gray-700 dark:text-gray-300 space-y-1">
              <li>Indirect, incidental, special, consequential, or punitive damages</li>
              <li>Loss of profits, revenue, data, or business opportunities</li>
              <li>Service interruptions or data loss</li>
              <li>Actions of third parties</li>
            </ul>
            <p className="text-gray-700 dark:text-gray-300">
              OUR TOTAL LIABILITY SHALL NOT EXCEED THE AMOUNT YOU PAID IN THE 12 MONTHS PRECEDING
              THE CLAIM.
            </p>
          </section>

          <section className="mb-8">
            <h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
              10. {t('legal:terms.section_10_title', 'Indemnification')}
            </h2>
            <p className="text-gray-700 dark:text-gray-300">
              You agree to indemnify and hold harmless {t('common:app.name', 'BakeWise')} from any claims, damages, losses,
              liabilities, and expenses (including legal fees) arising from:
            </p>
            <ul className="list-disc pl-6 mb-4 text-gray-700 dark:text-gray-300 space-y-1">
              <li>Your use of the Platform</li>
              <li>Your violation of these Terms</li>
              <li>Your violation of any law or rights of third parties</li>
              <li>Your User Content</li>
            </ul>
          </section>

          <section className="mb-8">
            <h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
              11. {t('legal:terms.section_11_title', 'Modifications to Terms')}
            </h2>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              We reserve the right to modify these Terms at any time. Changes will be effective:
            </p>
            <ul className="list-disc pl-6 mb-4 text-gray-700 dark:text-gray-300 space-y-1">
              <li>Immediately upon posting for non-material changes</li>
              <li>30 days after notification for material changes</li>
            </ul>
            <p className="text-gray-700 dark:text-gray-300">
              Continued use of the Platform after changes constitutes acceptance. If you do not agree,
              you must stop using the Platform and cancel your subscription.
            </p>
          </section>

          <section className="mb-8">
            <h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
              12. {t('legal:terms.section_12_title', 'Governing Law and Dispute Resolution')}
            </h2>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              12.1 Governing Law
            </h3>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              These Terms are governed by the laws of Spain and the European Union, without regard to
              conflict of law principles.
            </p>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              12.2 Dispute Resolution
            </h3>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              In the event of a dispute:
            </p>
            <ul className="list-disc pl-6 mb-4 text-gray-700 dark:text-gray-300 space-y-1">
              <li>First attempt to resolve through good faith negotiations</li>
              <li>If unresolved, disputes shall be submitted to the courts of Spain</li>
              <li>EU consumers retain rights under EU consumer protection laws</li>
            </ul>
          </section>

          <section className="mb-8">
            <h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
              13. {t('legal:terms.section_13_title', 'Miscellaneous')}
            </h2>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              13.1 Entire Agreement
            </h3>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              These Terms, together with our Privacy Policy and Cookie Policy, constitute the entire
              agreement between you and {t('common:app.name', 'BakeWise')}.
            </p>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              13.2 Severability
            </h3>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              If any provision is found unenforceable, the remaining provisions continue in full force.
            </p>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              13.3 Waiver
            </h3>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              Failure to enforce any right or provision does not constitute a waiver of such right.
            </p>

            <h3 className="text-xl font-semibold text-gray-900 dark:text-white mb-3">
              13.4 Assignment
            </h3>
            <p className="text-gray-700 dark:text-gray-300">
              You may not assign these Terms without our consent. We may assign these Terms without
              restriction.
            </p>
          </section>

          <section>
            <h2 className="text-2xl font-bold text-gray-900 dark:text-white mb-4">
              14. {t('legal:terms.section_14_title', 'Contact Information')}
            </h2>
            <p className="text-gray-700 dark:text-gray-300 mb-4">
              For questions about these Terms, contact us at:
            </p>
            <div className="bg-gray-50 dark:bg-gray-800 p-4 rounded-lg">
              <p className="font-semibold">{t('common:app.name', 'BakeWise')}</p>
              <p>Email: contact@bakewise.ai</p>
              <p>Website: https://bakewise.ai</p>
            </div>
          </section>
        </Card>

        <div className="mt-8 text-center">
          <a
            href="/"
            className="text-primary-600 hover:text-primary-700 dark:text-primary-400 dark:hover:text-primary-300 underline"
          >
            {t('common:actions.back_home', 'Back to Home')}
          </a>
        </div>
      </div>
    </div>
  );
};

export default TermsOfServicePage;
