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, Loader2 } from 'lucide-react'; import { Suspense } from 'react'; async function fetchHomeData() { try { const client = await createAdminClient(); // 1. Settings for count const settingsRes = await client.databases.listDocuments(APPWRITE_ALMEIRA_CONFIG.databaseId, 'settings', []); const postsCount = settingsRes.documents.length > 0 ? (settingsRes.documents[0].feed_count || settingsRes.documents[0].post_count || 9) : 9; // 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; } return { posts }; } catch (e) { console.error("Home fetch error", e); return { posts: [] }; } } export default async function Home() { const { posts } = 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 = null; if (post.imagen_destacada_id) { imagenUrl = `${ENDPOINT}/storage/buckets/${post.imagen_destacada_id.bucket_id}/files/${post.imagen_destacada_id.file_id}/preview?project=${PROJECT_ID}&width=800&height=500&quality=85`; } return ( ]*>?/gm, '') + '...'} tipo="Noticia" fecha={post.fecha_publicacion || post.$createdAt} imagenUrl={imagenUrl} /> ) })}
)}
); }