<?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 $files
 * @var $buttons
 * @var $urls
 */

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

<?php if (! $config['mod_down']): ?>
    <div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 mb-6 rounded-lg shadow-sm">
        <div class="flex items-center">
            <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
                <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/>
            </svg>
            <span class="font-medium"><?= __('Downloads are closed') ?></span>
        </div>
    </div>
<?php endif; ?>

<div class="flex flex-wrap gap-2 mb-6">
    <?php foreach ($buttons as $button): ?>
        <a href="<?= $button['url'] ?>" class="inline-flex items-center px-4 py-2 rounded-full text-sm font-medium transition-all duration-200 transform hover:scale-105 <?= $button['active'] ? 'bg-gradient-to-r from-blue-500 to-purple-600 text-white shadow-lg' : 'bg-white text-gray-700 border border-gray-300 hover:bg-gray-50 hover:shadow-md' ?>">
            <?= $button['name'] ?>
            <?php if ($button['active']): ?>
                <svg class="w-4 h-4 ml-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
                </svg>
            <?php endif; ?>
        </a>
    <?php endforeach; ?>
</div>

<?php if (empty($files)): ?>
    <div class="flex justify-center mb-6">
        <div class="w-full max-w-md">
            <div class="bg-blue-50 border-l-4 border-blue-400 p-4 rounded-lg shadow-sm">
                <div class="flex items-center">
                    <svg class="w-5 h-5 text-blue-400 mr-2" fill="currentColor" viewBox="0 0 20 20">
                        <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"/>
                    </svg>
                    <span class="text-blue-700"><?= __('List is empty') ?></span>
                </div>
            </div>
        </div>
    </div>
<?php endif; ?>

<div class="space-y-4">
    <?php foreach ($files as $file): ?>
        <?= $this->fetch('downloads::file_row', ['file' => $file]) ?>
    <?php endforeach; ?>
</div>

<div class="mt-6 pt-4 border-t border-gray-200">
    <a href="<?= $urls['downloads'] ?>" class="inline-flex items-center text-blue-600 hover:text-blue-800 font-medium transition-colors duration-200 hover:underline">
        <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/>
        </svg>
        <?= __('Downloads') ?>
    </a>
</div>