import React from 'react';
import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Alert } from 'react-native';
import { useAuth } from '@/contexts/AuthContext';
import { ThemedView } from '@/components/themed-view';
import { ThemedText } from '@/components/themed-text';

export default function AdminScreen() {
  const { user, logout } = useAuth();

  const handleLogout = () => {
    Alert.alert(
      'Déconnexion',
      'Êtes-vous sûr de vouloir vous déconnecter ?',
      [
        { text: 'Annuler', style: 'cancel' },
        { 
          text: 'Déconnexion', 
          style: 'destructive',
          onPress: logout
        }
      ]
    );
  };

  return (
    <ScrollView style={styles.container}>
      <ThemedView style={styles.content}>
        <View style={styles.header}>
          <ThemedText style={styles.title}>Administration</ThemedText>
          <ThemedText style={styles.subtitle}>
            Bonjour, {user?.prenom} {user?.nom}
          </ThemedText>
        </View>

        <View style={styles.section}>
          <ThemedText style={styles.sectionTitle}>Fonctionnalités d'administration</ThemedText>
          
          <View style={styles.card}>
            <Text style={styles.cardIcon}>✈️</Text>
            <ThemedText style={styles.cardTitle}>Gestion des Aéroports</ThemedText>
            <ThemedText style={styles.cardDescription}>
              Ajouter, modifier ou supprimer des aéroports
            </ThemedText>
          </View>

          <View style={styles.card}>
            <Text style={styles.cardIcon}>🗺️</Text>
            <ThemedText style={styles.cardTitle}>Gestion des Cartes</ThemedText>
            <ThemedText style={styles.cardDescription}>
              Upload et gestion des cartes et plans
            </ThemedText>
          </View>

          <View style={styles.card}>
            <Text style={styles.cardIcon}>📄</Text>
            <ThemedText style={styles.cardTitle}>Gestion des Documents</ThemedText>
            <ThemedText style={styles.cardDescription}>
              Upload et organisation des documents techniques
            </ThemedText>
          </View>

          <View style={styles.card}>
            <Text style={styles.cardIcon}>👥</Text>
            <ThemedText style={styles.cardTitle}>Gestion des Utilisateurs</ThemedText>
            <ThemedText style={styles.cardDescription}>
              Gérer les comptes utilisateurs et leurs rôles
            </ThemedText>
          </View>
        </View>

        <View style={styles.section}>
          <ThemedText style={styles.sectionTitle}>Informations système</ThemedText>
          
          <View style={styles.infoCard}>
            <ThemedText style={styles.infoLabel}>Rôle:</ThemedText>
            <ThemedText style={styles.infoValue}>{user?.role}</ThemedText>
          </View>
          
          <View style={styles.infoCard}>
            <ThemedText style={styles.infoLabel}>Email:</ThemedText>
            <ThemedText style={styles.infoValue}>{user?.email}</ThemedText>
          </View>
          
          <View style={styles.infoCard}>
            <ThemedText style={styles.infoLabel}>Statut:</ThemedText>
            <ThemedText style={styles.infoValue}>{user?.statut}</ThemedText>
          </View>
        </View>

        <TouchableOpacity style={styles.logoutButton} onPress={handleLogout}>
          <Text style={styles.logoutButtonText}>Se déconnecter</Text>
        </TouchableOpacity>
      </ThemedView>
    </ScrollView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#f5f5f5',
  },
  content: {
    flex: 1,
    padding: 20,
  },
  header: {
    marginBottom: 30,
  },
  title: {
    fontSize: 28,
    fontWeight: 'bold',
    color: '#2c3e50',
    marginBottom: 8,
  },
  subtitle: {
    fontSize: 16,
    color: '#7f8c8d',
  },
  section: {
    marginBottom: 30,
  },
  sectionTitle: {
    fontSize: 20,
    fontWeight: '600',
    color: '#2c3e50',
    marginBottom: 16,
  },
  card: {
    backgroundColor: '#fff',
    padding: 20,
    borderRadius: 12,
    marginBottom: 12,
    shadowColor: '#000',
    shadowOffset: {
      width: 0,
      height: 2,
    },
    shadowOpacity: 0.1,
    shadowRadius: 3.84,
    elevation: 5,
  },
  cardIcon: {
    fontSize: 24,
    marginBottom: 8,
  },
  cardTitle: {
    fontSize: 18,
    fontWeight: '600',
    color: '#2c3e50',
    marginBottom: 4,
  },
  cardDescription: {
    fontSize: 14,
    color: '#7f8c8d',
    lineHeight: 20,
  },
  infoCard: {
    backgroundColor: '#fff',
    padding: 16,
    borderRadius: 8,
    marginBottom: 8,
    flexDirection: 'row',
    justifyContent: 'space-between',
    alignItems: 'center',
  },
  infoLabel: {
    fontSize: 16,
    fontWeight: '500',
    color: '#2c3e50',
  },
  infoValue: {
    fontSize: 16,
    color: '#7f8c8d',
    textTransform: 'capitalize',
  },
  logoutButton: {
    backgroundColor: '#e74c3c',
    padding: 16,
    borderRadius: 8,
    alignItems: 'center',
    marginTop: 20,
  },
  logoutButtonText: {
    color: '#fff',
    fontSize: 16,
    fontWeight: '600',
  },
});
