import React from 'react';
import { View, Text, StyleSheet, ScrollView } from 'react-native';
import ScreenWrapper from '../components/ScreenWrapper';
import { colors, fonts, spacing } from '../utils/theme';

function Section({ title, children }) {
  return (
    <View style={styles.section}>
      <Text style={styles.sectionTitle}>{title}</Text>
      {children}
    </View>
  );
}

function Para({ children }) {
  return <Text style={styles.para}>{children}</Text>;
}

function Bullet({ children }) {
  return (
    <View style={styles.bulletRow}>
      <Text style={styles.bulletDot}>•</Text>
      <Text style={styles.bulletText}>{children}</Text>
    </View>
  );
}

export default function TermsScreen() {
  return (
    <ScreenWrapper>
      <ScrollView style={styles.scroll} contentContainerStyle={styles.content} showsVerticalScrollIndicator={false}>
        <Text style={styles.title}>Terms & Conditions</Text>
        <Text style={styles.updated}>Last updated: April 29, 2026</Text>

        <Section title="1. Acceptance of Terms">
          <Para>
            By downloading, installing, or using Nova40, you agree to be bound by these Terms and Conditions. If you do not agree, please do not use the application.
          </Para>
        </Section>

        <Section title="2. Description of Service">
          <Para>
            Nova40 is a 40-day identity transformation app that helps users build habits, track progress, and reflect on personal growth through AI-powered insights, journaling, and gamification.
          </Para>
        </Section>

        <Section title="3. User Accounts">
          <Para>To use Nova40, you must:</Para>
          <Bullet>Create an account with a valid email address</Bullet>
          <Bullet>Maintain the security of your account credentials</Bullet>
          <Bullet>Be at least 13 years of age</Bullet>
          <Para>
            You are responsible for all activity that occurs under your account.
          </Para>
        </Section>

        <Section title="4. User Content">
          <Para>
            You retain ownership of all content you create in Nova40, including your stories, journal entries, and reflections. By using the AI features, you grant us permission to process your content through third-party AI services for the purpose of generating personalized responses.
          </Para>
        </Section>

        <Section title="5. AI-Generated Content">
          <Para>
            Nova40 uses artificial intelligence to generate identity statements, habit suggestions, reflections, and transformation stories. You acknowledge that:
          </Para>
          <Bullet>AI-generated content is for guidance only, not professional advice</Bullet>
          <Bullet>AI responses may not always be accurate or appropriate</Bullet>
          <Bullet>You should not rely solely on AI content for mental health decisions</Bullet>
        </Section>

        <Section title="6. Acceptable Use">
          <Para>You agree not to:</Para>
          <Bullet>Use the app for any illegal or unauthorized purpose</Bullet>
          <Bullet>Attempt to hack, reverse engineer, or disrupt the service</Bullet>
          <Bullet>Submit content that is harmful, abusive, or violates others' rights</Bullet>
          <Bullet>Create multiple accounts to abuse free features</Bullet>
        </Section>

        <Section title="7. Intellectual Property">
          <Para>
            The Nova40 app, including its design, code, logos, and branding, is owned by Nova40 and protected by intellectual property laws. You may not copy, modify, or distribute any part of the application without written permission.
          </Para>
        </Section>

        <Section title="8. Disclaimer of Warranties">
          <Para>
            Nova40 is provided "as is" without warranties of any kind. We do not guarantee that the app will be uninterrupted, error-free, or that AI-generated content will meet your expectations.
          </Para>
        </Section>

        <Section title="9. Limitation of Liability">
          <Para>
            To the maximum extent permitted by law, Nova40 shall not be liable for any indirect, incidental, or consequential damages arising from your use of the application.
          </Para>
        </Section>

        <Section title="10. Health Disclaimer">
          <Para>
            Nova40 is a personal development tool and is not a substitute for professional medical, psychological, or therapeutic advice. If you are experiencing mental health issues, please consult a qualified professional.
          </Para>
        </Section>

        <Section title="11. Data and Privacy">
          <Para>
            Your use of Nova40 is also governed by our Privacy Policy. Please review it to understand how we collect and use your information.
          </Para>
        </Section>

        <Section title="12. Termination">
          <Para>
            We reserve the right to suspend or terminate your account at any time for violation of these terms. You may delete your account at any time through the app settings.
          </Para>
        </Section>

        <Section title="13. Changes to Terms">
          <Para>
            We may update these Terms and Conditions from time to time. Continued use of the app after changes constitutes acceptance of the updated terms.
          </Para>
        </Section>

        <Section title="14. Governing Law">
          <Para>
            These terms are governed by the laws of the Republic of Indonesia. Any disputes shall be resolved in the courts of Indonesia.
          </Para>
        </Section>

        <Section title="15. Contact">
          <Para>
            For questions about these Terms, contact us at: support@nova40.app
          </Para>
        </Section>
      </ScrollView>
    </ScreenWrapper>
  );
}

const styles = StyleSheet.create({
  scroll: { flex: 1 },
  content: { padding: spacing.lg, paddingBottom: spacing.xxl * 2 },
  title: { color: colors.text, fontSize: fonts.sizes.xxl, fontWeight: fonts.weights.bold, marginBottom: spacing.xs },
  updated: { color: colors.textMuted, fontSize: fonts.sizes.sm, marginBottom: spacing.xl },
  section: { marginBottom: spacing.xl },
  sectionTitle: { color: colors.text, fontSize: fonts.sizes.md, fontWeight: fonts.weights.bold, marginBottom: spacing.sm },
  para: { color: colors.textSecondary, fontSize: fonts.sizes.sm, lineHeight: 22, marginBottom: spacing.sm },
  bulletRow: { flexDirection: 'row', paddingLeft: spacing.sm, marginBottom: spacing.xs },
  bulletDot: { color: colors.primary, fontSize: fonts.sizes.sm, marginRight: spacing.sm, lineHeight: 22 },
  bulletText: { color: colors.textSecondary, fontSize: fonts.sizes.sm, lineHeight: 22, flex: 1 },
});
