<?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 $total
 * @var $urls
 * @var $pagination
 * @var $show_empty_info
 * @var $search_query
 */

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

<?php if (! $config['mod_down']): ?>
    <div class="alert alert-danger border-0 shadow">
        <?= __('Downloads are closed') ?>
    </div>
<?php endif; ?>

<form action="?act=search" method="post" class="mb-3">
    <div class="form-group">
        <label for="search_query"><?= __('Search query') ?></label>
        <input type="text" class="form-control" id="search_query" placeholder="<?= __('Search query') ?>"
               name="search" value="<?= $search_query ?>" maxlength="64" minlength="2" required>
    </div>
    <div class="form-group">
        <div class="custom-control custom-checkbox mb-3">
            <input type="checkbox" class="custom-control-input" name="id" value="1" id="search_t" <?= ($id ? 'checked="checked"' : '') ?>>
            <label class="custom-control-label" for="search_t"><?= __('Search in description') ?></label>
        </div>
    </div>
    <button type="submit" name="submit" value="1" class="btn btn-primary"><?= __('Search') ?></button>
</form>

<?php if (empty($files) && $show_empty_info): ?>
    <div class="alert alert-info"><?= __('List is empty') ?></div>
<?php endif; ?>

<?php foreach ($files as $file): ?>
    <?= $this->fetch('downloads::file_row', ['file' => $file]) ?>
<?php endforeach; ?>

<?php if ($total): ?>
    <div>
        <div><?= __('Total') ?>: <?= $total ?></div>
        <!-- Page switching -->
        <?php if ($total > $user->config->kmess): ?>
            <div class="mt-1"><?= $pagination ?></div>
        <?php endif ?>
    </div>
<?php endif; ?>

<?php if (empty($files)): ?>
    <div class="alert alert-info">
        <?= __('Search by file Name and is case insensitive.<br>The length of the request: 2 min. 64 max.') ?>
    </div>
<?php endif; ?>

<div class="mt-2">
    <div class="pb-2">
        <a href="?act=search"><?= __('New Search') ?></a>
    </div>

    <a href="<?= $urls['downloads'] ?>"><?= __('Downloads') ?></a>
</div>
