import { APPWRITE_ALMEIRA_CONFIG } from '@/lib/appwrite'; import { createAdminClient } from '@/lib/appwrite.server'; import { Query } from 'node-appwrite'; import { NewsCard } from '@/components/NewsCard'; import { GlobalSidebar, hasSidebarContent } from '@/components/AdWrappers'; import { Calendar } from 'lucide-react'; import { Settings } from '@/types/settings'; import { Post, MediaItem } from '@/types/publications'; async function fetchEventosData() { try { const client = await createAdminClient(); // 1. Settings const settingsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'settings', []); const settings = (settingsRes.documents.length > 0 ? settingsRes.documents[0] : { ticker_count: 10, rotation_seconds: 5, feed_news_count: 12, show_news_date: true }) as Settings; const postsCount = settings.feed_news_count || 12; const cardSettings = { showCategory: settings.news_card_show_category ?? false, showFooterDate: String(settings.show_news_date) === 'true', showFooterButton: settings.news_card_show_footer_button ?? true, footerText: settings.news_card_footer_text || "" }; // 2. Get EVENTO type ID const typeRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'publication_types', [ Query.equal('codigo', 'EVENTO') ]); let posts: Post[] = []; if (typeRes.documents.length > 0) { const firstType = typeRes.documents[0]; const typeId = firstType?.$id; if (!typeId) return { posts: [], cardSettings }; const postsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'posts', [ Query.equal('tipo_publicacion_id', typeId), Query.equal('estado', 'Publicado'), Query.orderDesc('fecha_publicacion'), Query.limit(postsCount) ]); posts = postsRes.documents as unknown as Post[]; // 3. Resolve Media const mediaIds = posts.map(p => p.imagen_destacada_id).filter(id => id && typeof id === 'string') as string[]; if (mediaIds.length > 0) { const mediaRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'media', [ Query.equal('$id', mediaIds) ]); const mediaMap = new Map(mediaRes.documents.map(m => [m.$id, m as unknown as MediaItem])); posts = posts.map(p => ({ ...p, resolved_media: mediaMap.get(p.imagen_destacada_id as string) })); } } return { posts, cardSettings }; } catch (e) { console.error("Eventos fetch error", e); return { posts: [], cardSettings: { showCategory: false, showFooterDate: true, showFooterButton: true, footerText: "" } }; } } export default async function EventosPage() { const { posts, cardSettings } = await fetchEventosData(); const hasSidebar = await hasSidebarContent(); return (
{/* Sci-Fi Hero Section */}

EVENTOS EN TU
REGIÓN

El primer portal transaccional de medios impulsado por inteligencia artificial. Los mejores eventos artísticos, culturales y sociales en un solo lugar.

Explorar Agenda
Próximos

Agenda de Eventos

{posts.length === 0 ? (

Sin Eventos Próximos

El portal se encuentra a la espera de nuevas programaciones en la región.

) : (
{posts.map((post) => { const PROJECT_ID = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '69b84df5003bd8957c5c'; const ENDPOINT = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://appwrite.almeira.com.co/v1'; let imagenUrl = post.og_image_url || null; if (post.resolved_media) { imagenUrl = `${ENDPOINT}/storage/buckets/${post.resolved_media.bucket_id}/files/${post.resolved_media.file_id}/preview?project=${PROJECT_ID}&width=800&height=500&quality=85`; } return ( ]*>?/gm, '').substring(0, 150) + '...'} tipo="Evento" fecha={post.fecha_publicacion || post.$createdAt} imagenUrl={imagenUrl} showCategory={cardSettings.showCategory} showFooterDate={cardSettings.showFooterDate} showFooterButton={cardSettings.showFooterButton} footerText={cardSettings.footerText} /> ) })}
)}
{hasSidebar && ( )}
); }