<?php
/**
 * Vista: Detalle de Noticia
 * @var array $noticia
 * @var array $articleSchema
 */
?>

<!-- Structured Data: NewsArticle -->
<script type="application/ld+json">
<?= json_encode($articleSchema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) ?>
</script>

<!-- Breadcrumb -->
<nav class="mb-6" aria-label="Breadcrumb">
    <ol class="flex items-center space-x-2 text-sm text-gray-500" itemscope itemtype="https://schema.org/BreadcrumbList">
        <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
            <a href="/" itemprop="item" class="hover:text-primary-600 transition"><span itemprop="name">Inicio</span></a>
            <meta itemprop="position" content="1">
        </li>
        <li aria-hidden="true"><span class="mx-1">/</span></li>
        <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
            <a href="/<?= strtolower(htmlspecialchars($noticia['categoria'])) ?>" itemprop="item" class="hover:text-primary-600 transition"><span itemprop="name"><?= htmlspecialchars($noticia['categoria']) ?></span></a>
            <meta itemprop="position" content="2">
        </li>
        <li aria-hidden="true"><span class="mx-1">/</span></li>
        <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
            <span class="text-gray-900 font-medium truncate max-w-[200px]" itemprop="name" aria-current="page"><?= htmlspecialchars($noticia['titulo']) ?></span>
            <meta itemprop="position" content="3">
        </li>
    </ol>
</nav>

<article class="max-w-4xl mx-auto" itemscope itemtype="https://schema.org/NewsArticle">
    <!-- Encabezado -->
    <header class="mb-8">
        <span class="inline-block bg-primary-100 text-primary-700 text-xs font-bold uppercase tracking-wider px-3 py-1 rounded-full mb-4" itemprop="articleSection">
            <?= htmlspecialchars($noticia['categoria']) ?>
        </span>
        <h1 class="text-3xl md:text-4xl font-extrabold text-gray-900 leading-tight mb-4" itemprop="headline">
            <?= htmlspecialchars($noticia['titulo']) ?>
        </h1>
        <p class="sr-only" itemprop="description"><?= htmlspecialchars($noticia['resumen']) ?></p>

        <div class="flex flex-wrap items-center text-gray-500 text-sm space-x-4 mb-6">
            <span class="flex items-center" itemprop="author" itemscope itemtype="https://schema.org/Person">
                <svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path></svg>
                <span itemprop="name"><?= htmlspecialchars($noticia['autor']) ?></span>
            </span>
            <time class="flex items-center" datetime="<?= htmlspecialchars($noticia['fechaISO']) ?>T12:00:00-05:00" itemprop="datePublished">
                <svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"></path></svg>
                <?= htmlspecialchars($noticia['fecha']) ?>
            </time>
            <meta itemprop="dateModified" content="<?= htmlspecialchars($noticia['fechaISO']) ?>T12:00:00-05:00">
        </div>

        <!-- Breadcrumb list schema via microdata (ya arriba) -->
    </header>

    <!-- Imagen -->
    <figure class="mb-8" itemprop="image" itemscope itemtype="https://schema.org/ImageObject">
        <img
            src="<?= htmlspecialchars($noticia['imagen']) ?>"
            alt="<?= htmlspecialchars($noticia['imagenAlt'] ?? $noticia['titulo']) ?>"
            class="w-full rounded-2xl shadow-lg object-cover max-h-[500px]"
            width="800"
            height="450"
            itemprop="url"
            loading="eager"
        >
        <meta itemprop="width" content="800">
        <meta itemprop="height" content="450">
    </figure>

    <!-- Resumen destacado -->
    <div class="bg-gray-50 border-l-4 border-accent p-6 rounded-r-lg mb-8">
        <p class="text-lg text-gray-700 font-medium leading-relaxed italic" itemprop="description">
            <?= htmlspecialchars($noticia['resumen']) ?>
        </p>
    </div>

    <!-- Contenido -->
    <div class="prose-content" itemprop="articleBody">
        <?= $noticia['contenido'] ?>
    </div>

    <!-- Publisher -->
    <div class="mt-8 pt-6 border-t border-gray-200">
        <div class="flex items-center" itemprop="publisher" itemscope itemtype="https://schema.org/NewsMediaOrganization">
            <div class="w-10 h-10 bg-primary-600 rounded-full flex items-center justify-center mr-3">
                <span class="text-white font-bold text-sm">NH</span>
            </div>
            <div>
                <p class="text-sm font-semibold text-gray-900" itemprop="name">Noticias de Hoy Online</p>
                <p class="text-xs text-gray-500">Medio de noticias digitales</p>
            </div>
        </div>
    </div>

    <!-- Compartir -->
    <div class="border-t border-gray-200 mt-8 pt-8">
        <h2 class="text-sm font-semibold text-gray-900 uppercase tracking-wider mb-4">Compartir esta noticia</h2>
        <div class="flex flex-wrap gap-3">
            <a href="https://www.facebook.com/sharer/sharer.php?u=<?= urlencode($pageUrl ?? '') ?>" target="_blank" rel="noopener noreferrer" class="inline-flex items-center px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm font-medium rounded-lg transition" aria-label="Compartir en Facebook">
                <svg class="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true"><path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"/></svg>
                Facebook
            </a>
            <a href="https://twitter.com/intent/tweet?url=<?= urlencode($pageUrl ?? '') ?>&text=<?= urlencode($noticia['titulo']) ?>" target="_blank" rel="noopener noreferrer" class="inline-flex items-center px-4 py-2 bg-sky-500 hover:bg-sky-600 text-white text-sm font-medium rounded-lg transition" aria-label="Compartir en X (Twitter)">
                <svg class="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>
                X (Twitter)
            </a>
            <a href="https://wa.me/?text=<?= urlencode($noticia['titulo'] . ' ' . ($pageUrl ?? '')) ?>" target="_blank" rel="noopener noreferrer" class="inline-flex items-center px-4 py-2 bg-green-600 hover:bg-green-700 text-white text-sm font-medium rounded-lg transition" aria-label="Compartir en WhatsApp">
                <svg class="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/></svg>
                WhatsApp
            </a>
            <a href="https://telegram.me/share/url?url=<?= urlencode($pageUrl ?? '') ?>&text=<?= urlencode($noticia['titulo']) ?>" target="_blank" rel="noopener noreferrer" class="inline-flex items-center px-4 py-2 bg-blue-400 hover:bg-blue-500 text-white text-sm font-medium rounded-lg transition" aria-label="Compartir en Telegram">
                <svg class="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true"><path d="M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.479.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z"/></svg>
                Telegram
            </a>
        </div>
    </div>

    <!-- Article meta oculto para SEO -->
    <meta itemprop="mainEntityOfPage" content="<?= htmlspecialchars($pageUrl ?? '') ?>">
</article>
