import { useReservations } from "@/features/reservations/hooks/useReservations"; import { useAuthSession } from "@/providers/AuthProvider"; import theme from "@/theme"; import { Feather, MaterialIcons } from "@expo/vector-icons"; import { Link } from "expo-router"; import { useMemo } from "react"; import { ActivityIndicator, Pressable, StyleSheet, Text, View, } from "react-native"; function formatDate(date: string): string { const parsedDate = new Date(date); // formato fecha return parsedDate.toLocaleDateString("es-ES", { day: "2-digit", month: "short", year: "numeric", }); } // creacion de acceso rapidos al theme de estilos const { colors, spacing, radius, typography, fontWeight, layout, shadows } = theme; export default function HomeScreen() { const { user } = useAuthSession(); const { reservations, activeReservations, loading, error } = useReservations(); // crea el contador de reservas en el mes actual const currentMonthReservationsCount = useMemo(() => { const now = new Date(); const currentMonth = now.getMonth(); const currentYear = now.getFullYear(); return reservations.filter((reservation) => { const reservationDate = new Date(reservation.date); return ( reservationDate.getMonth() === currentMonth && reservationDate.getFullYear() === currentYear ); }).length; }, [reservations]); // crea una lista con las 2 primeras reservas activas const previewReservations = useMemo( () => activeReservations.slice(0, 2), [activeReservations], ); if (loading) { return ( ); } if (error) { return ( {error} ); } return ( // pantalla inicio {/* cabecera de bienvenida */} Hola{user?.displayName ? `, ${user.displayName}` : ""} 👋 Bienvenido a la App Oficina {/* seccion de accesos rapidos */} Accesos rápidos Reservar{"\n"}espacio Mis reservas{"\n"}activas {/* sección de reservas activas */} Reservas activas Ver todas {">"} {previewReservations.length > 0 ? ( previewReservations.map((reservation) => ( {reservation.officeName} {">"} {formatDate(reservation.date)} {reservation.startTime} - {reservation.endTime} {reservation.checkInAt ? "Confirmada" : "Pendiente"} )) ) : ( No tienes reservas activas en este momento. )} {/* seccion de estadisticas */} Estadísticas de uso {activeReservations.length} Reservas activas {currentMonthReservationsCount} Este mes {reservations.length} Total ); } const styles = StyleSheet.create({ // el ancho del container esta acotado si se toca hacerlo en el menuBar tambien container: { flex: 1, paddingHorizontal: spacing.xl, paddingTop: spacing.lg, paddingBottom: spacing.xl, gap: 18, maxWidth: layout.contentWidth, width: "100%", alignSelf: "center", backgroundColor: colors.background, }, center: { flex: 1, alignItems: "center", justifyContent: "center", padding: spacing.xxxl, backgroundColor: colors.background, }, // estilos de cabecera title: { fontSize: typography.xxxl, fontWeight: fontWeight.medium, color: colors.text, }, subtitle: { fontSize: typography.xl, color: colors.muted, }, divider: { height: 1, backgroundColor: colors.divider, marginVertical: spacing.md, }, // estilos de la seccion de accesos rapidos sectionTitle: { fontSize: typography.xxl, fontWeight: fontWeight.semibold, color: colors.text, }, quickAccessSection: { gap: spacing.lg, }, quickAccessRow: { flexDirection: "row", gap: spacing.lg, }, quickAccessButton: { flex: 1, backgroundColor: colors.primary, paddingVertical: spacing.xxxl, borderRadius: radius.xl, alignItems: "center", justifyContent: "center", gap: spacing.md, minHeight: 120, }, quickAccessButtonDark: { flex: 1, backgroundColor: colors.primaryDark, paddingVertical: spacing.xxxl, borderRadius: radius.xl, alignItems: "center", justifyContent: "center", gap: spacing.md, minHeight: 112, }, // --- estilos textos accesos rapidos quickAccessButtonText: { color: colors.white, fontWeight: fontWeight.regular, fontSize: typography.md, textAlign: "center", lineHeight: 16, }, //---------------------------------- quickAccessIconContainerLight: { width: 40, height: 40, borderRadius: radius.md, backgroundColor: "#3b82f6", alignItems: "center", justifyContent: "center", }, quickAccessIconContainerDark: { width: 40, height: 40, borderRadius: radius.md, backgroundColor: "#334e68", alignItems: "center", justifyContent: "center", }, // estilos de reservas activas reservationsHeader: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", }, linkRow: { flexDirection: "row", alignItems: "center", gap: spacing.xs, }, chevronSmall: { fontSize: typography.lg, color: colors.primary, fontWeight: fontWeight.semibold, }, linkText: { color: colors.primary, fontWeight: fontWeight.regular, }, reservationsList: { gap: spacing.xl, }, // estilos tarjetas de reservas activas reservationCard: { backgroundColor: colors.surface, borderRadius: radius.xxl, padding: spacing.xl, gap: spacing.md, minHeight: 100, ...shadows.card, }, reservationContent: { flexDirection: "row", gap: spacing.lg, }, reservationIconContainer: { width: 48, height: 48, borderRadius: radius.lg, backgroundColor: colors.primarySoft, alignItems: "center", justifyContent: "center", }, reservationInfo: { flex: 1, gap: spacing.sm, }, reservationHeader: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", }, reservationOffice: { fontSize: 18, fontWeight: fontWeight.medium, color: colors.text, }, chevron: { fontSize: 18, color: colors.textSecondary, fontWeight: fontWeight.semibold, }, reservationMetaRow: { flexDirection: "row", alignItems: "center", gap: spacing.sm, }, reservationMeta: { color: colors.textSecondary, fontSize: typography.md, }, reservationRow: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", }, reservationTime: { color: colors.text, fontSize: typography.lg, flex: 1, }, statusBadge: { alignSelf: "flex-start", backgroundColor: colors.successBg, paddingHorizontal: 10, paddingVertical: spacing.xs, borderRadius: radius.sm, }, // estado confirmada (verde) statusConfirmed: { backgroundColor: colors.successBg, }, statusTextConfirmed: { color: colors.successText, }, // estado pendiente (gris neutro) statusPending: { backgroundColor: "#EEF2F6", }, statusTextPending: { color: "#475569", }, statusText: { color: colors.successText, fontWeight: fontWeight.semibold, fontSize: typography.sm, }, emptyReservationCard: { borderWidth: 1, borderColor: colors.border, borderRadius: radius.xxl, padding: spacing.xl, backgroundColor: colors.surface, }, emptyReservationText: { color: colors.textSecondary, textAlign: "center", }, //estilos estadisticas statsHeader: { marginBottom: spacing.md, }, statsGrid: { flexDirection: "row", gap: spacing.lg, }, statCard: { flex: 1, borderWidth: 1, borderColor: colors.border, borderRadius: radius.xxl, paddingVertical: 18, paddingHorizontal: spacing.lg, minHeight: 115, backgroundColor: colors.surface, gap: spacing.sm, alignItems: "center", justifyContent: "space-between", }, // --- estilos textos estadisticas statValue: { fontSize: typography.xxxl, fontWeight: fontWeight.regular, color: colors.text, }, statLabel: { color: colors.textSecondary, fontSize: typography.sm, fontWeight: fontWeight.regular, textAlign: "center", }, //-------------------------------- error: { color: colors.error, textAlign: "center", }, });