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 } from '@/components/AdWrappers'; import { RadioTower, Sparkles, ChevronDown } from 'lucide-react'; async function fetchHomeData() { try { const client = await createAdminClient(); // 1. Settings const settingsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'settings', []); const settings: any = settingsRes.documents.length > 0 ? settingsRes.documents[0] : {}; const postsCount = settings.feed_count || settings.post_count || 9; const cardSettings = { showCategory: settings.news_card_show_category ?? false, showFooterDate: settings.news_card_show_footer_date ?? true, showFooterButton: settings.news_card_show_footer_button ?? true, footerText: settings.news_card_footer_text || "" }; // 2. Get NOTICIA type ID const typeRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'publication_types', [ Query.equal('codigo', 'NOTICIA') ]); let posts: any[] = []; if (typeRes.documents.length > 0) { const typeId = typeRes.documents[0].$id; 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; // 3. Resolve Media documents for images const mediaIds = posts.map(p => p.imagen_destacada_id).filter(id => id && typeof id === '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])); posts = posts.map(p => ({ ...p, resolved_media: mediaMap.get(p.imagen_destacada_id) })); } } return { posts, cardSettings }; } catch (e) { console.error("Home fetch error", e); return { posts: [], cardSettings: { showCategory: false, showFooterDate: true, footerText: "" } }; } } export default async function Home() { const { posts, cardSettings } = await fetchHomeData(); return (
{/* Sci-Fi Hero Section */}
{/* Dynamic Orbs background */}
Señal En Vivo 24/7

NOTICIAS AL
SIGUIENTE NIVEL

El primer portal transaccional hiperconectado. Sumérgete en la actualidad de la región en tiempo real con una interfaz sin precedentes.

EXPLORAR CONTENIDO
{/* Scroll Indicator */} Descubrir
{/* Feed Section */}
Último Minuto

Feed de Noticias

{posts.length === 0 ? (

Sin Conexión Reciente

El portal se encuentra a la espera de señales desde el núcleo central.

) : (
{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="Noticia" fecha={post.fecha_publicacion || post.$createdAt} imagenUrl={imagenUrl} showCategory={cardSettings.showCategory} showFooterDate={cardSettings.showFooterDate} showFooterButton={cardSettings.showFooterButton} footerText={cardSettings.footerText} /> ) })}
)}
{hasSidebar && ( )}
); }