<?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 Mobicms\Render\Template\Template $this
 * @var $title
 * @var $page_title
 * @var $data
 */

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


<?php if (empty($data['items'])): ?>
    <?= $this->fetch(
        'system::app/alert',
        [
            'alert_type' => 'alert-info',
            'alert'      => __('The list is empty'),
        ]
    ) ?>
<?php else: ?>
    <?php if ($user->isValid()): ?>
        <form action="<?= $data['form_action'] ?>" method="post">
    <?php endif; ?>
    <div class="row">
        <div class="col-md-6">

            <?php if (! empty($data['user_smiles_current'])): ?>
                <div class="alert alert-info">
                    <a href="?act=my_smilies"><?= __('My smilies') ?></a>
                    (<?= $data['user_smiles_current'] ?> / <?= $data['user_smiles_max'] ?>)
                </div>
            <?php endif; ?>

            <div class="list-group">
                <?php foreach ($data['items'] as $item): ?>
                    <div class="list-group-item d-flex align-items-center">
                        <div class="custom-control custom-checkbox align-items-center mr-2">
                            <input type="checkbox" class="custom-control-input" name="add_sm[]"
                                   value="<?= $item['lat_smile'] ?>" id="check_<?= $item['lat_smile'] ?>" <?= ! $item['can_add'] ? 'disabled' : '' ?>>
                            <label class="custom-control-label" for="check_<?= $item['lat_smile'] ?>"></label>
                        </div>
                        <div class="mr-3">
                            <img src="<?= $item['picture'] ?>" alt="<?= $item['smile'] ?>">
                        </div>
                        <div>
                            :<?= $item['lat_smile'] ?>: <?= __('or') ?> :<?= $item['smile'] ?>:
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </div>
    </div>
    <?php if ($user->isValid()): ?>
        <div class="mt-3">
            <input type="submit" name="add" value="<?= __('Add') ?>" class="btn btn-primary">
        </div>
        </form>
    <?php endif; ?>
<?php endif; ?>

<div class="mt-4">
    <?php if ($data['total'] > $user->config->kmess): ?>
        <div>
            <?= $data['pagination'] ?>
        </div>
    <?php endif; ?>
    <?php if ($data['total'] > 0): ?>
        <div><?= __('Total:') ?> <?= $data['total'] ?></div>
    <?php endif; ?>
</div>
<div>
    <a href="<?= $data['back_url'] ?>"><?= __('Back') ?></a>
</div>
