<?php

/**
 * @var Mobicms\Render\Template\Template $this
 * @var string $collection_name
 * @var array<int, array<string, mixed>> $items
 * @var string $add_url
 * @var string $back_url
 * @var string $pagination
 * @var string $success_message
 */

$this->layout('system::layout/default');
?>

<?php if ($success_message !== ''): ?>
    <?= $this->fetch('system::app/alert', ['alert_type' => 'alert-success', 'alert' => $this->e($success_message)]) ?>
<?php endif; ?>

<div class="mb-2 text-muted"><?= __('Collection') ?>: <b><?= $this->e($collection_name) ?></b></div>

<div class="mb-3">
    <a href="<?= $this->e($add_url) ?>" class="btn btn-primary btn-sm"><?= __('New item') ?></a>
</div>

<?php if (empty($items)): ?>
    <?= $this->fetch('system::app/alert', ['alert_type' => 'alert-info', 'alert' => __('The list is empty')]) ?>
<?php else: ?>
    <?php foreach ($items as $item): ?>
        <div class="new_post-item without_avatar">
            <div class="d-flex justify-content-between align-items-center">
                <div class="d-flex align-items-center">
                    <span class="text-muted me-1">[<?= (int) $item['sort'] ?>]</span>
                    <a href="<?= $this->e($item['edit_url']) ?>" class="h3 mb-0"><?= $this->e($item['name']) ?></a>
                    <span class="badge rounded-pill text-bg-light border ms-2"><?= $this->e($item['code']) ?></span>
                </div>
                <div>
                    <?php if ($item['active']): ?>
                        <span class="badge rounded-pill bg-success"><?= __('On') ?></span>
                    <?php else: ?>
                        <span class="badge rounded-pill bg-danger"><?= __('Off') ?></span>
                    <?php endif; ?>
                </div>
            </div>
            <div class="mt-2">
                <a href="<?= $this->e($item['edit_url']) ?>"><?= __('Edit') ?></a>
                <a href="<?= $this->e($item['delete_url']) ?>" class="text-danger ms-2"><?= __('Delete') ?></a>
            </div>
        </div>
    <?php endforeach; ?>
<?php endif; ?>

<div class="mt-4"><?= $pagination ?></div>

<div class="mt-2">
    <a href="<?= $this->e($back_url) ?>"><?= __('Back') ?></a>
</div>
