import React from 'react';
import { View, Text, StyleSheet, ScrollView } from 'react-native';
import ScreenWrapper from '../components/ScreenWrapper';
import { colors, fonts, spacing, borderRadius } 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 PrivacyPolicyScreen() {
  return (
    <ScreenWrapper>
      <ScrollView style={styles.scroll} contentContainerStyle={styles.content} showsVerticalScrollIndicator={false}>
        <Text style={styles.title}>Privacy Policy</Text>
        <Text style={styles.updated}>Last updated: April 29, 2026</Text>

        <Section title="1. Introduction">
          <Para>
            Nova40 ("we", "our", "us") is committed to protecting your privacy. This Privacy Policy explains how we collect, use, and safeguard your information when you use our mobile application.
          </Para>
        </Section>

        <Section title="2. Information We Collect">
          <Para>We collect the following types of information:</Para>
          <Bullet>Account information (email address, password)</Bullet>
          <Bullet>Identity and habit data you create within the app</Bullet>
          <Bullet>Daily journal entries, mood data, and reflections</Bullet>
          <Bullet>Game scores and progress statistics</Bullet>
          <Bullet>Device information for crash reporting (via Firebase Crashlytics)</Bullet>
        </Section>

        <Section title="3. How We Use Your Information">
          <Para>Your information is used to:</Para>
          <Bullet>Provide and maintain the Nova40 service</Bullet>
          <Bullet>Generate AI-powered identity reflections and habit suggestions</Bullet>
          <Bullet>Track your 40-day transformation progress</Bullet>
          <Bullet>Improve app stability through crash reports</Bullet>
          <Bullet>Send important service notifications</Bullet>
        </Section>

        <Section title="4. AI-Generated Content">
          <Para>
            Nova40 uses artificial intelligence (Google Gemini / Claude AI) to generate personalized identity statements, habit suggestions, and daily reflections. Your story and journal entries are sent to AI services for processing. We do not store AI-processed data on third-party servers beyond the generation session.
          </Para>
        </Section>

        <Section title="5. Data Storage">
          <Para>
            Your data is stored securely using Supabase (cloud database) and locally on your device via AsyncStorage. Data stored locally remains on your device and is not transmitted unless you explicitly use cloud features.
          </Para>
        </Section>

        <Section title="6. Data Sharing">
          <Para>We do not sell, trade, or share your personal information with third parties, except:</Para>
          <Bullet>Firebase (Google) — for crash reporting and analytics</Bullet>
          <Bullet>AI service providers — for generating personalized content</Bullet>
          <Bullet>When required by law or legal process</Bullet>
        </Section>

        <Section title="7. Data Security">
          <Para>
            We implement industry-standard security measures to protect your data, including encrypted connections (HTTPS), secure authentication, and row-level security policies on our database.
          </Para>
        </Section>

        <Section title="8. Your Rights">
          <Para>You have the right to:</Para>
          <Bullet>Access your personal data</Bullet>
          <Bullet>Delete your account and all associated data</Bullet>
          <Bullet>Export your journal and progress data</Bullet>
          <Bullet>Opt out of analytics collection</Bullet>
        </Section>

        <Section title="9. Data Retention">
          <Para>
            We retain your data as long as your account is active. When you delete your account or reset your journey, associated data is permanently removed from our systems.
          </Para>
        </Section>

        <Section title="10. Children's Privacy">
          <Para>
            Nova40 is not intended for children under 13 years of age. We do not knowingly collect information from children under 13.
          </Para>
        </Section>

        <Section title="11. Changes to This Policy">
          <Para>
            We may update this Privacy Policy from time to time. Changes will be posted within the app and take effect immediately upon posting.
          </Para>
        </Section>

        <Section title="12. Contact Us">
          <Para>
            If you have questions about this Privacy Policy, please 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 },
});
