import React from 'react'; import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, Platform } from 'react-native'; import Animated, { FadeInUp } from 'react-native-reanimated'; import { useBarbearia, Appointment } from '../../stores/BarbeariaContext'; import { useLanguage } from '../../stores/LanguageContext'; import { Card } from '../../components/ui/Card'; import { COLORS, SPACING, TYPOGRAPHY, BORDER_RADIUS, SHADOWS } from '../../constants/theme'; import { Check, X, Calendar, Clock, User, Scissors, Settings, DollarSign } from 'lucide-react-native'; import { router } from 'expo-router'; export default function AdminDashboard() { const { barbearia, updateAppointmentStatus, activeBarberId, loginBarber } = useBarbearia(); const { language, t, formatPrice } = useLanguage(); const appointments = barbearia?.appointments || []; // Use theme colors const themeColors = barbearia?.colors || COLORS; const primaryColor = themeColors.primary; const activeBarber = barbearia?.barbers?.find(b => b.id === activeBarberId); const isOwner = !activeBarberId; const canViewFinance = isOwner || activeBarber?.permissions?.canViewFinance; const canEditConfig = isOwner || activeBarber?.permissions?.canEditConfig; // Filtra agendamentos: o dono vê todos, o barbeiro vê apenas os dele const visibleAppointments = isOwner ? appointments : appointments.filter(a => a.barberId === activeBarberId); const pendingAppointments = visibleAppointments.filter(a => a.status === 'pending'); const acceptedAppointments = visibleAppointments.filter(a => a.status === 'accepted'); const getServiceName = (id: string) => { const s = barbearia?.services.find(service => service.id === id); if (!s) return 'Serviço'; return language === 'pt' ? s.nomePt : s.nomeEs; }; const getBarberName = (id: string) => barbearia?.barbers.find(b => b.id === id)?.nome || 'Barbeiro'; const renderAppointment = (item: Appointment, index: number) => ( {item.clientName} {item.status === 'pending' ? t('admin.dashboard.pending_badge') || 'Pendente' : t('admin.dashboard.confirmed_badge') || 'Confirmado'} {item.date} {item.time} {item.serviceIds.map(getServiceName).join(', ')} • {getBarberName(item.barberId)} Total: {formatPrice(item.totalPt, item.totalEs)} {item.status === 'pending' ? ( updateAppointmentStatus(item.id, 'rejected')} > {t('admin.dashboard.reject')} updateAppointmentStatus(item.id, 'accepted')} > {t('admin.dashboard.accept')} ) : ( { const confirmCancel = Platform.OS === 'web' ? window.confirm(t('admin.dashboard.cancel_confirm') || 'Deseja realmente cancelar este agendamento?') : true; if (confirmCancel) { updateAppointmentStatus(item.id, 'rejected'); } }} > {t('admin.dashboard.cancel') || 'Cancelar'} )} ); return ( {t('admin.dashboard.title', { name: barbearia?.nome || 'Barbeiro' })} {t('admin.dashboard.pending', { count: pendingAppointments.length })} {canViewFinance && ( router.push('/admin/finance')}> )} router.push('/admin/agenda')}> {canEditConfig && ( router.push('/admin/config')}> )} { if (!isOwner) { loginBarber(null); } router.replace('/landing'); }}> {pendingAppointments.length > 0 && ( {t('admin.dashboard.waiting')} {pendingAppointments.map((item, i) => renderAppointment(item, i))} )} {t('admin.dashboard.upcoming')} {acceptedAppointments.length > 0 ? acceptedAppointments.map((item, i) => renderAppointment(item, i + pendingAppointments.length)) : ( {t('admin.dashboard.empty')} )} ); } const styles = StyleSheet.create({ container: { flex: 1 }, header: { paddingHorizontal: SPACING.lg, paddingVertical: SPACING.xl, paddingTop: Platform.OS === 'ios' ? 60 : 40, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', borderBottomLeftRadius: BORDER_RADIUS.lg, borderBottomRightRadius: BORDER_RADIUS.lg, ...(SHADOWS.medium as any), zIndex: 10, }, headerTextContainer: { flex: 1, marginRight: SPACING.md, }, title: { ...TYPOGRAPHY.h3, marginBottom: 2 }, subtitle: { ...TYPOGRAPHY.bodySmall }, headerActions: { flexDirection: 'row', gap: SPACING.xs }, iconButton: { width: 40, height: 40, borderRadius: 20, alignItems: 'center', justifyContent: 'center', }, content: { padding: SPACING.md, paddingBottom: 100 }, section: { marginBottom: SPACING.xl }, sectionTitle: { ...TYPOGRAPHY.h4, marginBottom: SPACING.md }, appointmentCard: { marginBottom: SPACING.sm, padding: SPACING.md }, cardHeader: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: SPACING.sm }, userInfo: { flexDirection: 'row', alignItems: 'center', gap: SPACING.xs, flex: 1 }, avatarPlaceholder: { width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', }, clientName: { ...TYPOGRAPHY.body, fontWeight: '700', flex: 1 }, statusBadge: { paddingHorizontal: 8, paddingVertical: 4, borderRadius: BORDER_RADIUS.sm }, statusText: { fontSize: 10, fontWeight: '800', textTransform: 'uppercase' }, statusPending: { backgroundColor: 'rgba(234, 179, 8, 0.15)' }, statusAccepted: { backgroundColor: 'rgba(34, 197, 94, 0.15)' }, details: { flexDirection: 'row', gap: SPACING.md, marginBottom: 4 }, detailItem: { flexDirection: 'row', alignItems: 'center', gap: 4 }, detailText: { ...TYPOGRAPHY.caption, fontSize: 11 }, servicesList: { flexDirection: 'row', alignItems: 'center', gap: 6, marginBottom: SPACING.md }, servicesText: { ...TYPOGRAPHY.caption, fontWeight: '600', flex: 1 }, priceInfo: { marginBottom: SPACING.sm }, priceText: { ...TYPOGRAPHY.bodySmall, fontWeight: '700' }, actions: { flexDirection: 'row', gap: SPACING.sm, borderTopWidth: 1, paddingTop: SPACING.sm }, actionBtn: { flex: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 4, paddingVertical: 8, borderRadius: BORDER_RADIUS.md, borderWidth: 1 }, actionTextReject: { color: '#FF4444', fontWeight: 'bold', fontSize: 12 }, actionTextAccept: { color: '#22C55E', fontWeight: 'bold', fontSize: 12 }, actionTextCancel: { fontWeight: '600', fontSize: 12 }, rejectBtn: { borderColor: 'rgba(255, 68, 68, 0.3)', backgroundColor: 'rgba(255, 68, 68, 0.05)' }, acceptBtn: { borderColor: 'rgba(34, 197, 94, 0.3)', backgroundColor: 'rgba(34, 197, 94, 0.05)' }, cancelBtn: { borderStyle: 'dashed' }, emptyText: { ...TYPOGRAPHY.bodySmall, textAlign: 'center', marginTop: SPACING.lg } });