<?php

/**
 * This file is part of JohnCMS Content Management System.
 *
 * @copyright JohnCMS Community
 * @license   https://opensource.org/licenses/GPL-3.0 GPL-3.0
 * @link      https://johncms.com JohnCMS Project
 */

/**
 * @var $title
 * @var $page_title
 * @var $data
 */

$this->layout(
    'system::layout/default',
    [
        'title'      => $title,
        'page_title' => $page_title ?? $title,
    ]
);
?>

<!-- Main Container -->
<div class="max-w-4xl mx-auto p-4 space-y-6">

    <!-- Header Section -->
    <div class="bg-gradient-to-r from-green-500 to-emerald-600 rounded-2xl shadow-lg overflow-hidden">
        <div class="p-6 text-white">
            <div class="flex items-center space-x-3 mb-2">
                <svg class="w-8 h-8 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"/>
                </svg>
                <h1 class="text-2xl font-bold"><?= $page_title ?? $title ?></h1>
            </div>
            <p class="text-green-100 text-sm opacity-90">
                <?= __('Discover the latest additions to our library collection') ?>
            </p>
        </div>
    </div>

    <?php if ($total) : ?>
        <!-- Articles List -->
        <div class="space-y-6">
            <?php foreach ($list() as $newlist): ?>
                <div class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-200 dark:border-gray-700 hover:shadow-md transition duration-200 overflow-hidden group">
                    <div class="p-6">
                        <!-- Article Title -->
                        <a href="?id=<?= $newlist['id'] ?>" class="block mb-4">
                            <h3 class="text-xl font-bold text-gray-900 dark:text-white group-hover:text-blue-600 dark:group-hover:text-blue-400 transition duration-200 leading-tight">
                                <?= $newlist['name'] ?>
                            </h3>
                        </a>

                        <!-- Announce/Description -->
                        <?php if (!empty($newlist['announce'])): ?>
                            <div class="mb-4">
                                <p class="text-gray-600 dark:text-gray-400 leading-relaxed line-clamp-3">
                                    <?= $newlist['announce'] ?>
                                </p>
                            </div>
                        <?php endif; ?>

                        <!-- Metadata -->
                        <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 pt-4 border-t border-gray-100 dark:border-gray-700">
                            <div class="flex flex-wrap items-center gap-4 text-sm text-gray-500 dark:text-gray-400">
                                <!-- Section -->
                                <div class="flex items-center space-x-2">
                                    <svg class="w-4 h-4 flex-shrink-0 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"/>
                                    </svg>
                                    <span class="font-medium text-gray-700 dark:text-gray-300"><?= __('Section:') ?></span>
                                    <a href="?do=dir&amp;id=<?= $newlist['cat_id'] ?>" class="text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-300 transition duration-200">
                                        <?= $newlist['catalog_name'] ?>
                                    </a>
                                </div>

                                <!-- Author -->
                                <div class="flex items-center space-x-2">
                                    <svg class="w-4 h-4 flex-shrink-0 text-purple-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <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"/>
                                    </svg>
                                    <span class="font-medium text-gray-700 dark:text-gray-300"><?= __('Author:') ?></span>
                                    <span class="text-gray-600 dark:text-gray-400"><?= $newlist['who'] ?></span>
                                </div>

                                <!-- Rating -->
                                <div class="flex items-center space-x-2">
                                    <svg class="w-4 h-4 flex-shrink-0 text-yellow-500" fill="currentColor" viewBox="0 0 20 20">
                                        <path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"/>
                                    </svg>
                                    <span class="font-medium text-gray-700 dark:text-gray-300"><?= __('Rating:') ?></span>
                                    <span class="text-gray-600 dark:text-gray-400"><?= $newlist['ratingView'] ?></span>
                                </div>
                            </div>

                            <!-- Comments -->
                            <?php if ($newlist['comments']) : ?>
                                <div class="flex items-center space-x-2">
                                    <a href="?act=comments&amp;id=<?= $newlist['id'] ?>" 
                                       class="inline-flex items-center px-3 py-1 bg-red-50 dark:bg-red-900/20 text-red-700 dark:text-red-400 rounded-lg hover:bg-red-100 dark:hover:bg-red-900/30 transition duration-200 font-medium text-sm">
                                        <svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"/>
                                        </svg>
                                        <?= __('Comments:') ?>
                                        <span class="ml-1 bg-red-100 dark:bg-red-800 text-red-800 dark:text-red-200 text-xs font-medium px-2 py-0.5 rounded-full">
                                            <?= $newlist['comm_count'] ?>
                                        </span>
                                    </a>
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>

        <!-- Statistics and Pagination -->
        <div class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-200 dark:border-gray-700 p-6">
            <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
                <!-- Total Count -->
                <div class="flex items-center space-x-3">
                    <div class="w-10 h-10 bg-green-100 dark:bg-green-900/30 rounded-lg flex items-center justify-center">
                        <svg class="w-5 h-5 text-green-600 dark:text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
                        </svg>
                    </div>
                    <div>
                        <div class="text-sm font-medium text-gray-700 dark:text-gray-300"><?= __('Total Articles') ?></div>
                        <div class="text-2xl font-bold text-gray-900 dark:text-white"><?= $total ?></div>
                    </div>
                </div>

                <!-- Pagination -->
                <?php if ($total > $user->config->kmess) : ?>
                    <div class="flex items-center">
                        <?= $pagination ?>
                    </div>
                <?php endif ?>
            </div>
        </div>

    <?php else: ?>
        <!-- Empty State -->
        <div class="bg-white dark:bg-gray-800 rounded-2xl shadow-sm border border-gray-200 dark:border-gray-700 p-12 text-center">
            <div class="w-24 h-24 mx-auto mb-6 text-gray-300 dark:text-gray-600">
                <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.746 0 3.332.477 4.5 1.253v13C19.832 18.477 18.246 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"/>
                </svg>
            </div>
            <h3 class="text-2xl font-bold text-gray-900 dark:text-white mb-3"><?= __('No New Articles') ?></h3>
            <p class="text-gray-500 dark:text-gray-400 max-w-md mx-auto mb-6">
                <?= __('There are no new articles in the library at the moment. Check back later for new additions.') ?>
            </p>
        </div>
    <?php endif; ?>

    <!-- Navigation -->
    <div class="text-center">
        <a href="?" class="inline-flex items-center px-6 py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-xl shadow-sm hover:shadow-md transition duration-200 font-medium">
            <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"/>
            </svg>
            <?= __('To Library') ?>
        </a>
    </div>

</div>