'use client';

import { Box, Container, Typography, Paper } from '@mui/material';
import Link from 'next/link';
import { AppShell } from '@/components/layouts/AppShell/AppShell';
import { ProtectedRoute } from '@/components/common/ProtectedRoute';

export default function TermsOfServicePage() {
  const lastUpdated = 'October 4, 2025';

  return (
    <ProtectedRoute>
      <AppShell>
        <Container maxWidth="md" sx={{ py: 4 }}>
      <Paper elevation={0} sx={{ p: 4, border: 1, borderColor: 'divider' }}>
        <Typography variant="h3" component="h1" gutterBottom>
          Terms of Service
        </Typography>

        <Typography variant="body2" color="text.secondary" paragraph>
          Last Updated: {lastUpdated}
        </Typography>

        <Box sx={{ mt: 4 }}>
          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            1. Acceptance of Terms
          </Typography>
          <Typography paragraph>
            By accessing or using ParentFlow (the "Service"), you agree to be bound by these Terms of Service ("Terms").
            If you do not agree to these Terms, do not use the Service.
          </Typography>
          <Typography paragraph>
            These Terms constitute a legally binding agreement between you and ParentFlow ("we," "us," or "our").
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            2. Description of Service
          </Typography>
          <Typography paragraph>
            ParentFlow is a parenting organization and tracking application designed to help parents and caregivers manage
            childcare for children aged 0-6 years. The Service includes:
          </Typography>
          <Typography component="div" paragraph>
            <ul>
              <li>Activity tracking (feeding, sleep, diapers, medicine, milestones)</li>
              <li>AI-powered parenting support and guidance</li>
              <li>Family synchronization and collaboration tools</li>
              <li>Analytics and insights about your child's patterns</li>
              <li>Voice input capabilities</li>
              <li>Photo storage and milestone tracking</li>
            </ul>
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            3. User Accounts
          </Typography>

          <Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
            3.1 Account Creation
          </Typography>
          <Typography paragraph>
            To use the Service, you must create an account. You agree to:
          </Typography>
          <Typography component="div" paragraph>
            <ul>
              <li>Provide accurate and complete information</li>
              <li>Maintain the security of your account credentials</li>
              <li>Notify us immediately of any unauthorized access</li>
              <li>Be responsible for all activities under your account</li>
            </ul>
          </Typography>

          <Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
            3.2 Age Requirements
          </Typography>
          <Typography paragraph>
            You must be at least 18 years old (or the age of majority in your jurisdiction) to create an account.
            Users between 13-17 years old may only use the Service with parental consent.
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            4. Acceptable Use
          </Typography>
          <Typography paragraph>
            You agree NOT to:
          </Typography>
          <Typography component="div" paragraph>
            <ul>
              <li>Use the Service for any illegal purpose</li>
              <li>Violate any laws or regulations</li>
              <li>Infringe on intellectual property rights</li>
              <li>Upload malicious code or viruses</li>
              <li>Attempt to gain unauthorized access to our systems</li>
              <li>Harass, abuse, or harm other users</li>
              <li>Share inappropriate content involving minors</li>
              <li>Use automated tools to access the Service (bots, scrapers)</li>
              <li>Reverse engineer or decompile the Service</li>
            </ul>
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            5. Medical Disclaimer
          </Typography>
          <Typography paragraph sx={{ fontWeight: 'bold', color: 'error.main' }}>
            THE SERVICE IS NOT A SUBSTITUTE FOR PROFESSIONAL MEDICAL ADVICE.
          </Typography>
          <Typography paragraph>
            Our AI assistant and tracking features provide general information and insights only. They do not constitute
            medical advice, diagnosis, or treatment. Always consult with qualified healthcare professionals for medical concerns.
          </Typography>
          <Typography component="div" paragraph>
            <strong>In case of emergency, call your local emergency services immediately.</strong>
            <ul>
              <li>United States: 911</li>
              <li>United Kingdom: 999</li>
              <li>European Union: 112</li>
            </ul>
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            6. User Content
          </Typography>

          <Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
            6.1 Your Content
          </Typography>
          <Typography paragraph>
            You retain ownership of all content you upload to the Service (photos, data, messages).
            By uploading content, you grant us a license to use, store, and process it to provide the Service.
          </Typography>

          <Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
            6.2 Content Responsibility
          </Typography>
          <Typography paragraph>
            You are solely responsible for your content. You represent that you have the necessary rights and permissions
            to upload and share your content, including photos of your children.
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            7. Intellectual Property
          </Typography>
          <Typography paragraph>
            The Service, including its design, features, code, and content (excluding user content), is owned by ParentFlow
            and protected by copyright, trademark, and other intellectual property laws.
          </Typography>
          <Typography paragraph>
            You may not copy, modify, distribute, sell, or create derivative works based on the Service without our written permission.
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            8. Subscription and Payment
          </Typography>

          <Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
            8.1 Free and Premium Features
          </Typography>
          <Typography paragraph>
            We offer both free and premium subscription tiers. Premium features may include unlimited AI queries, advanced analytics,
            and priority support.
          </Typography>

          <Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
            8.2 Billing
          </Typography>
          <Typography paragraph>
            Premium subscriptions are billed monthly or annually. Payments are processed through third-party payment processors.
            By subscribing, you authorize us to charge your payment method.
          </Typography>

          <Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
            8.3 Cancellation and Refunds
          </Typography>
          <Typography paragraph>
            You may cancel your subscription at any time. Cancellations take effect at the end of the current billing period.
            We do not offer refunds for partial subscription periods, except as required by law.
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            9. Privacy
          </Typography>
          <Typography paragraph>
            Your use of the Service is also governed by our{' '}
            <Link href="/legal/privacy" style={{ color: 'inherit', fontWeight: 'bold' }}>
              Privacy Policy
            </Link>
            . Please review it to understand how we collect, use, and protect your information.
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            10. Termination
          </Typography>

          <Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
            10.1 Termination by You
          </Typography>
          <Typography paragraph>
            You may terminate your account at any time through the app settings. Upon termination, your data will be deleted
            in accordance with our Privacy Policy.
          </Typography>

          <Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
            10.2 Termination by Us
          </Typography>
          <Typography paragraph>
            We reserve the right to suspend or terminate your account if you violate these Terms or engage in harmful behavior.
            We will provide notice where reasonably possible.
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            11. Disclaimers
          </Typography>
          <Typography paragraph sx={{ fontWeight: 'bold' }}>
            THE SERVICE IS PROVIDED "AS IS" AND "AS AVAILABLE" WITHOUT WARRANTIES OF ANY KIND.
          </Typography>
          <Typography paragraph>
            We disclaim all warranties, express or implied, including warranties of merchantability, fitness for a particular purpose,
            and non-infringement. We do not guarantee that the Service will be error-free, secure, or uninterrupted.
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            12. Limitation of Liability
          </Typography>
          <Typography paragraph>
            TO THE MAXIMUM EXTENT PERMITTED BY LAW, WE SHALL NOT BE LIABLE FOR ANY INDIRECT, INCIDENTAL, CONSEQUENTIAL, OR PUNITIVE
            DAMAGES ARISING FROM YOUR USE OF THE SERVICE.
          </Typography>
          <Typography paragraph>
            Our total liability shall not exceed the amount you paid us in the 12 months preceding the claim, or $100, whichever is greater.
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            13. Indemnification
          </Typography>
          <Typography paragraph>
            You agree to indemnify and hold harmless ParentFlow and its officers, directors, employees, and agents from any claims,
            damages, or expenses arising from your use of the Service or violation of these Terms.
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            14. Dispute Resolution
          </Typography>

          <Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
            14.1 Informal Resolution
          </Typography>
          <Typography paragraph>
            Before filing a legal claim, you agree to contact us at <strong>hello@parentflow.com</strong> to attempt to resolve
            the dispute informally.
          </Typography>

          <Typography variant="h6" gutterBottom sx={{ mt: 2 }}>
            14.2 Arbitration
          </Typography>
          <Typography paragraph>
            Any disputes that cannot be resolved informally will be settled by binding arbitration in accordance with the
            American Arbitration Association rules, except where prohibited by law.
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            15. Governing Law
          </Typography>
          <Typography paragraph>
            These Terms are governed by the laws of [Your Jurisdiction], without regard to conflict of law principles.
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            16. Changes to Terms
          </Typography>
          <Typography paragraph>
            We may update these Terms from time to time. We will notify you of material changes by email or through the app.
            Your continued use of the Service after changes constitutes acceptance of the updated Terms.
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            17. Severability
          </Typography>
          <Typography paragraph>
            If any provision of these Terms is found to be invalid or unenforceable, the remaining provisions will continue in full force.
          </Typography>

          <Typography variant="h5" gutterBottom sx={{ mt: 3 }}>
            18. Contact Us
          </Typography>
          <Typography paragraph>
            If you have questions about these Terms, please contact us:
          </Typography>
          <Typography component="div" paragraph>
            <strong>Email:</strong> hello@parentflow.com<br />
            <strong>Address:</strong> Serbota 3, Bucharest, Romania
          </Typography>

          <Box sx={{ mt: 4, pt: 3, borderTop: 1, borderColor: 'divider' }}>
            <Typography variant="body2" color="text.secondary">
              Related Legal Documents:
            </Typography>
            <Box sx={{ display: 'flex', gap: 2, mt: 1, flexWrap: 'wrap' }}>
              <Link href="/legal/privacy" style={{ textDecoration: 'none' }}>
                <Typography color="primary" sx={{ '&:hover': { textDecoration: 'underline' } }}>
                  Privacy Policy
                </Typography>
              </Link>
              <Link href="/legal/eula" style={{ textDecoration: 'none' }}>
                <Typography color="primary" sx={{ '&:hover': { textDecoration: 'underline' } }}>
                  EULA
                </Typography>
              </Link>
              <Link href="/legal/cookies" style={{ textDecoration: 'none' }}>
                <Typography color="primary" sx={{ '&:hover': { textDecoration: 'underline' } }}>
                  Cookie Policy
                </Typography>
              </Link>
            </Box>
          </Box>
        </Box>
      </Paper>
    </Container>
      </AppShell>
    </ProtectedRoute>
  );
}
