import React, { useState, useEffect } from 'react'; import { View, Text, StyleSheet, Image, ScrollView, TouchableOpacity, TextInput, Platform, Alert, Switch } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import Animated, { FadeInUp, FadeInDown, FadeIn, FadeOut } from 'react-native-reanimated'; import * as ImagePicker from 'expo-image-picker'; import { COLORS, SPACING, TYPOGRAPHY, BORDER_RADIUS, SHADOWS } from '../../../constants/theme'; import { Card } from '../../../components/ui/Card'; import { Button } from '../../../components/ui/Button'; import { User, Settings, CreditCard, Bell, LogOut, ChevronRight, ChevronDown, Camera, Check, X, Plus, Languages, RefreshCw, FileText } from 'lucide-react-native'; import { useLanguage } from '../../../stores/LanguageContext'; import { useBarbearia } from '../../../stores/BarbeariaContext'; import { router, useLocalSearchParams } from 'expo-router'; import AsyncStorage from '@react-native-async-storage/async-storage'; export default function ProfileScreen() { const { t, language, setLanguage } = useLanguage(); const { barbearia } = useBarbearia(); const { slug } = useLocalSearchParams(); const colors = barbearia?.colors || COLORS; const primaryColor = colors.primary; const [isEditing, setIsEditing] = useState(false); const [name, setName] = useState('Cliente VIP'); const [email, setEmail] = useState('cliente@email.com'); const [phone, setPhone] = useState('(00) 00000-0000'); const [photo, setPhoto] = useState('https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?w=400'); const [cards, setCards] = useState([{ id: '1', last4: '4242', brand: 'Visa' }]); // Accordion State const [expandedSection, setExpandedSection] = useState(null); // Notification States const [notifySms, setNotifySms] = useState(true); const [notifyEmail, setNotifyEmail] = useState(true); const [notifyReminder, setNotifyReminder] = useState(true); // Carregar dados salvos localmente useEffect(() => { AsyncStorage.getItem('@barber_client_profile').then(data => { if (data) { const parsed = JSON.parse(data); if (parsed.name) setName(parsed.name); if (parsed.email) setEmail(parsed.email); if (parsed.phone) setPhone(parsed.phone); if (parsed.photo) setPhoto(parsed.photo); if (parsed.cards) setCards(parsed.cards); if (parsed.notifications) { setNotifySms(parsed.notifications.sms); setNotifyEmail(parsed.notifications.email); setNotifyReminder(parsed.notifications.reminder); } } }); }, []); const saveProfile = async (updates: any) => { const current = { name, email, phone, photo, cards, notifications: { sms: notifySms, email: notifyEmail, reminder: notifyReminder }, ...updates }; await AsyncStorage.setItem('@barber_client_profile', JSON.stringify(current)); }; const handleSaveEdit = () => { setIsEditing(false); saveProfile({ name, email, phone }); }; const pickImage = async () => { const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync(); if (status !== 'granted') { Alert.alert('Permissão necessária', 'Precisamos de acesso à sua galeria.'); return; } const result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.Images, allowsEditing: true, aspect: [1, 1], quality: 0.5, base64: true, }); if (!result.canceled && result.assets[0].base64) { const newPhoto = `data:image/jpeg;base64,${result.assets[0].base64}`; setPhoto(newPhoto); saveProfile({ photo: newPhoto }); } }; const handleAddCard = () => { if (Platform.OS === 'web') { const last4 = window.prompt('Digite os 4 últimos dígitos do cartão:'); if (last4 && last4.length === 4) { const newCard = { id: Math.random().toString(), last4, brand: 'Mastercard' }; const newCards = [...cards, newCard]; setCards(newCards); saveProfile({ cards: newCards }); } } else { Alert.prompt('Novo Cartão', 'Digite os 4 últimos dígitos:', [ { text: 'Cancelar', style: 'cancel' }, { text: 'Adicionar', onPress: (text) => { if (text && text.length >= 4) { const newCard = { id: Math.random().toString(), last4: text.slice(-4), brand: 'Mastercard' }; const newCards = [...cards, newCard]; setCards(newCards); saveProfile({ cards: newCards }); } } } ]); } }; const removeCard = (id: string) => { const newCards = cards.filter(c => c.id !== id); setCards(newCards); saveProfile({ cards: newCards }); }; const handleLogout = () => { router.replace(`/${slug}/(auth)/login`); }; const handleClearCache = () => { if (Platform.OS === 'web') { window.alert('Dados sincronizados com sucesso!'); } else { Alert.alert('Sucesso', 'Aplicativo sincronizado e cache limpo.'); } }; // Calcula estatísticas reais baseadas no histórico do barbearia (simulação usando appointments globais) const myAppointments = barbearia?.appointments?.filter(a => a.status === 'accepted') || []; const cutsCount = myAppointments.length; let points = 0; myAppointments.forEach(a => { points += (a.serviceIds.length * 5); }); const displayCuts = cutsCount > 0 ? cutsCount : 0; const displayPoints = points > 0 ? points : 0; return ( {/* Profile Header */} {isEditing ? (