<?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,
    ]
);
$this->sectionReplace('sidebar-menu', $this->fetch('admin::sidebar-admin-menu', ['module_menu' => ['counters' => true]]));
?>

<?php if (! empty($data['message'])): ?>
    <?= $this->fetch(
        'system::app/alert',
        [
            'alert_type' => 'alert-info',
            'alert'      => $data['message'],
        ]
    ) ?>
<?php endif; ?>

<?php if (empty($data['items'])): ?>
    <?= $this->fetch(
        'system::app/alert',
        [
            'alert_type' => 'alert-info',
            'alert'      => __('The list is empty'),
        ]
    ) ?>
<?php endif; ?>
<?php foreach ($data['items'] as $item): ?>
    <div class="new_post-item without_avatar">
        <div class="d-flex justify-content-between align-items-center">
            <a href="?mod=view&amp;id=<?= $item['id'] ?>" class="h3"><?= $item['name'] ?></a>
            <div>
                <?php if ($item['switch'] === 1): ?>
                    <a href="?mod=view&amp;go=off&amp;id=<?= $item['id'] ?>" class="badge badge-pill badge-success"><?= __('On') ?></a>
                <?php else: ?>
                    <a href="?mod=view&amp;go=on&amp;id=<?= $item['id'] ?>" class="badge badge-pill badge-danger"><?= __('Off') ?></a>
                <?php endif; ?>
            </div>
        </div>
        <div class="mt-2">
            <a href="?mod=up&amp;id=<?= $item['id'] ?>" class="mr-2"><?= __('Up') ?></a>
            <a href="?mod=down&amp;id=<?= $item['id'] ?>" class="mr-2"><?= __('Down') ?></a>
            <a href="?mod=edit&amp;id=<?= $item['id'] ?>" class="mr-2"><?= __('Edit') ?></a>
            <a href="?mod=del&amp;id=<?= $item['id'] ?>" class="mr-2 text-danger"><?= __('Delete') ?></a>
        </div>
    </div>
<?php endforeach; ?>

<div class="mt-2">
    <?php if ($data['total'] > 0): ?>
        <div class="mb-2"><?= __('Total:') ?> <?= $data['total'] ?></div>
    <?php endif; ?>
    <a href="?mod=edit" class="btn btn-primary"><?= __('Add') ?></a>
</div>
<div class="mt-2">
    <a href="<?= $data['back_url'] ?>"><?= __('Back') ?></a>
</div>
