import React from 'react';
import {
  View,
  Text,
  StyleSheet,
  ScrollView,
} from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { SafeAreaView } from 'react-native-safe-area-context';
import { AppColors, BorderRadius, FontSizes, Spacing } from '@/constants/theme';
import { PageHeader } from '@/components/PageHeader';

interface PrivacyHighlightProps {
  icon: keyof typeof Ionicons.glyphMap;
  iconColor: string;
  iconBgColor: string;
  title: string;
  description: string;
}

function PrivacyHighlight({
  icon,
  iconColor,
  iconBgColor,
  title,
  description,
}: PrivacyHighlightProps) {
  return (
    <View style={styles.highlight}>
      <View style={[styles.highlightIcon, { backgroundColor: iconBgColor }]}>
        <Ionicons name={icon} size={20} color={iconColor} />
      </View>
      <View style={styles.highlightContent}>
        <Text style={styles.highlightTitle}>{title}</Text>
        <Text style={styles.highlightDescription}>{description}</Text>
      </View>
    </View>
  );
}

export default function PrivacyPolicyScreen() {
  return (
    <SafeAreaView style={styles.container} edges={['top', 'bottom']}>
      <PageHeader title="Privacy Policy" />
      <ScrollView showsVerticalScrollIndicator={false}>
        {/* Highlights */}
        <View style={styles.highlightsSection}>
          <Text style={styles.highlightsSectionTitle}>Our Privacy Commitment</Text>
          <View style={styles.highlightsCard}>
            <PrivacyHighlight
              icon="lock-closed"
              iconColor="#10B981"
              iconBgColor="#D1FAE5"
              title="End-to-End Encryption"
              description="All data is encrypted in transit and at rest"
            />
            <View style={styles.highlightDivider} />
            <PrivacyHighlight
              icon="shield-checkmark"
              iconColor="#3B82F6"
              iconBgColor="#DBEAFE"
              title="HIPAA Compliant"
              description="Healthcare-grade data protection standards"
            />
            <View style={styles.highlightDivider} />
            <PrivacyHighlight
              icon="close-circle"
              iconColor="#EF4444"
              iconBgColor="#FEE2E2"
              title="No Data Sales"
              description="We never sell your personal information"
            />
            <View style={styles.highlightDivider} />
            <PrivacyHighlight
              icon="trash"
              iconColor="#8B5CF6"
              iconBgColor="#EDE9FE"
              title="Right to Deletion"
              description="You can delete your data at any time"
            />
          </View>
        </View>

        {/* Full Policy */}
        <View style={styles.content}>
          <Text style={styles.lastUpdated}>Last Updated: December 2024</Text>

          <Text style={styles.sectionTitle}>1. Information We Collect</Text>
          <Text style={styles.paragraph}>
            WellNuo collects information to provide and improve our elderly care monitoring
            service. We collect:
          </Text>

          <Text style={styles.subSectionTitle}>Account Information</Text>
          <Text style={styles.bulletPoint}>• Name and contact information</Text>
          <Text style={styles.bulletPoint}>• Login credentials (encrypted)</Text>
          <Text style={styles.bulletPoint}>• Payment information (processed by secure third parties)</Text>

          <Text style={styles.subSectionTitle}>Beneficiary Data</Text>
          <Text style={styles.bulletPoint}>• Activity and motion sensor data</Text>
          <Text style={styles.bulletPoint}>• Location information (if enabled)</Text>
          <Text style={styles.bulletPoint}>• Health metrics from connected devices</Text>
          <Text style={styles.bulletPoint}>• Daily routines and patterns</Text>

          <Text style={styles.subSectionTitle}>Usage Data</Text>
          <Text style={styles.bulletPoint}>• App usage statistics</Text>
          <Text style={styles.bulletPoint}>• Device information</Text>
          <Text style={styles.bulletPoint}>• Error logs and performance data</Text>

          <Text style={styles.sectionTitle}>2. How We Use Your Information</Text>
          <Text style={styles.paragraph}>
            We use collected information to:
          </Text>
          <Text style={styles.bulletPoint}>• Provide real-time monitoring and alerts</Text>
          <Text style={styles.bulletPoint}>• Generate wellness scores and insights</Text>
          <Text style={styles.bulletPoint}>• Improve our AI algorithms (anonymized data only)</Text>
          <Text style={styles.bulletPoint}>• Send notifications and communications</Text>
          <Text style={styles.bulletPoint}>• Prevent fraud and ensure security</Text>
          <Text style={styles.bulletPoint}>• Comply with legal obligations</Text>

          <Text style={styles.sectionTitle}>3. Data Sharing</Text>
          <Text style={styles.paragraph}>
            We do NOT sell your personal information. We may share data with:
          </Text>
          <Text style={styles.bulletPoint}>• Authorized caregivers (your permission required)</Text>
          <Text style={styles.bulletPoint}>• Healthcare providers (with explicit consent)</Text>
          <Text style={styles.bulletPoint}>• Emergency services (in emergency situations)</Text>
          <Text style={styles.bulletPoint}>• Service providers (under strict contracts)</Text>
          <Text style={styles.bulletPoint}>• Legal authorities (when required by law)</Text>

          <Text style={styles.sectionTitle}>4. Data Security</Text>
          <Text style={styles.paragraph}>
            We implement industry-leading security measures:
          </Text>
          <Text style={styles.bulletPoint}>• AES-256 encryption for data at rest</Text>
          <Text style={styles.bulletPoint}>• TLS 1.3 encryption for data in transit</Text>
          <Text style={styles.bulletPoint}>• Regular security audits and penetration testing</Text>
          <Text style={styles.bulletPoint}>• Multi-factor authentication options</Text>
          <Text style={styles.bulletPoint}>• Automatic security patching</Text>
          <Text style={styles.bulletPoint}>• SOC 2 Type II certified infrastructure</Text>

          <Text style={styles.sectionTitle}>5. Data Retention</Text>
          <Text style={styles.paragraph}>
            We retain your data for:
          </Text>
          <Text style={styles.bulletPoint}>• Active accounts: Duration of service + 2 years</Text>
          <Text style={styles.bulletPoint}>• Deleted accounts: 30 days (recovery period)</Text>
          <Text style={styles.bulletPoint}>• Legal requirements: As required by law</Text>
          <Text style={styles.bulletPoint}>• Anonymized data: May be retained indefinitely for research</Text>

          <Text style={styles.sectionTitle}>6. Your Rights</Text>
          <Text style={styles.paragraph}>
            Under GDPR, CCPA, and other privacy laws, you have the right to:
          </Text>
          <Text style={styles.bulletPoint}>• Access your personal data</Text>
          <Text style={styles.bulletPoint}>• Correct inaccurate data</Text>
          <Text style={styles.bulletPoint}>• Delete your data ("right to be forgotten")</Text>
          <Text style={styles.bulletPoint}>• Export your data (data portability)</Text>
          <Text style={styles.bulletPoint}>• Opt out of marketing communications</Text>
          <Text style={styles.bulletPoint}>• Restrict processing of your data</Text>

          <Text style={styles.sectionTitle}>7. Children's Privacy</Text>
          <Text style={styles.paragraph}>
            WellNuo is designed for adult caregivers monitoring elderly individuals. We do
            not knowingly collect information from children under 13. If we discover such
            data has been collected, we will delete it immediately.
          </Text>

          <Text style={styles.sectionTitle}>8. International Data Transfers</Text>
          <Text style={styles.paragraph}>
            Data may be transferred to and processed in countries outside your residence.
            We ensure adequate safeguards through:
          </Text>
          <Text style={styles.bulletPoint}>• Standard Contractual Clauses (SCCs)</Text>
          <Text style={styles.bulletPoint}>• Privacy Shield certification (where applicable)</Text>
          <Text style={styles.bulletPoint}>• Data Processing Agreements with vendors</Text>

          <Text style={styles.sectionTitle}>9. Cookies and Tracking</Text>
          <Text style={styles.paragraph}>
            Our mobile app uses minimal tracking:
          </Text>
          <Text style={styles.bulletPoint}>• Essential cookies for authentication</Text>
          <Text style={styles.bulletPoint}>• Analytics (anonymized, opt-out available)</Text>
          <Text style={styles.bulletPoint}>• No third-party advertising trackers</Text>

          <Text style={styles.sectionTitle}>10. Changes to This Policy</Text>
          <Text style={styles.paragraph}>
            We may update this Privacy Policy periodically. We will notify you of material
            changes via email or in-app notification at least 30 days before they take effect.
          </Text>

          <Text style={styles.sectionTitle}>11. Contact Us</Text>
          <Text style={styles.paragraph}>
            For privacy-related questions or to exercise your rights:
          </Text>
          <View style={styles.contactCard}>
            <Text style={styles.contactTitle}>Privacy Officer</Text>
            <Text style={styles.contactInfo}>Email: privacy@wellnuo.com</Text>
            <Text style={styles.contactInfo}>Address: 123 Care Street, San Francisco, CA 94102</Text>
            <Text style={styles.contactInfo}>Phone: +1 (555) 123-4567</Text>
          </View>

          <View style={styles.footer}>
            <Text style={styles.footerText}>
              Your privacy matters to us. If you have any concerns about how we handle your
              data, please don't hesitate to contact us.
            </Text>
          </View>
        </View>
      </ScrollView>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: AppColors.surface,
  },
  highlightsSection: {
    backgroundColor: AppColors.background,
    paddingVertical: Spacing.lg,
  },
  highlightsSectionTitle: {
    fontSize: FontSizes.lg,
    fontWeight: '600',
    color: AppColors.textPrimary,
    textAlign: 'center',
    marginBottom: Spacing.md,
  },
  highlightsCard: {
    marginHorizontal: Spacing.lg,
  },
  highlight: {
    flexDirection: 'row',
    alignItems: 'center',
    paddingVertical: Spacing.sm,
  },
  highlightIcon: {
    width: 40,
    height: 40,
    borderRadius: BorderRadius.md,
    justifyContent: 'center',
    alignItems: 'center',
  },
  highlightContent: {
    flex: 1,
    marginLeft: Spacing.md,
  },
  highlightTitle: {
    fontSize: FontSizes.base,
    fontWeight: '500',
    color: AppColors.textPrimary,
  },
  highlightDescription: {
    fontSize: FontSizes.xs,
    color: AppColors.textMuted,
    marginTop: 2,
  },
  highlightDivider: {
    height: 1,
    backgroundColor: AppColors.border,
    marginLeft: 40 + Spacing.md,
    marginVertical: Spacing.xs,
  },
  content: {
    padding: Spacing.lg,
    backgroundColor: AppColors.background,
    marginTop: Spacing.md,
  },
  lastUpdated: {
    fontSize: FontSizes.sm,
    color: AppColors.textMuted,
    marginBottom: Spacing.lg,
    textAlign: 'center',
  },
  sectionTitle: {
    fontSize: FontSizes.lg,
    fontWeight: '600',
    color: AppColors.textPrimary,
    marginTop: Spacing.lg,
    marginBottom: Spacing.sm,
  },
  subSectionTitle: {
    fontSize: FontSizes.base,
    fontWeight: '500',
    color: AppColors.textPrimary,
    marginTop: Spacing.md,
    marginBottom: Spacing.xs,
  },
  paragraph: {
    fontSize: FontSizes.sm,
    color: AppColors.textSecondary,
    lineHeight: 22,
    marginBottom: Spacing.sm,
  },
  bulletPoint: {
    fontSize: FontSizes.sm,
    color: AppColors.textSecondary,
    lineHeight: 22,
    marginLeft: Spacing.md,
    marginBottom: 4,
  },
  contactCard: {
    backgroundColor: AppColors.surface,
    borderRadius: BorderRadius.lg,
    padding: Spacing.md,
    marginTop: Spacing.sm,
  },
  contactTitle: {
    fontSize: FontSizes.base,
    fontWeight: '600',
    color: AppColors.textPrimary,
    marginBottom: Spacing.sm,
  },
  contactInfo: {
    fontSize: FontSizes.sm,
    color: AppColors.textSecondary,
    marginBottom: 4,
  },
  footer: {
    marginTop: Spacing.xl,
    paddingTop: Spacing.lg,
    borderTopWidth: 1,
    borderTopColor: AppColors.border,
  },
  footerText: {
    fontSize: FontSizes.xs,
    color: AppColors.textMuted,
    textAlign: 'center',
    fontStyle: 'italic',
  },
});
