{* Title *}
{$meta_title = 'Блог' scope=root}

{* Container *}
<div class="container-fluid">

    {* Title *}
    <div class="nk-block-head nk-block-head-sm">
        <div class="nk-block-between">
            <div class="nk-block-head-content">
                <h3 class="nk-block-title page-title">Блог</h3>
                <div class="nk-block-des text-soft">
                    <p>Управление блогом сайта.</p>
                </div>
            </div>
            <div class="nk-block-head-content">
                <div class="toggle-wrap nk-block-tools-toggle">

                    {* Mobile toogle btn *}
                    <a href="#" class="btn btn-icon btn-trigger toggle-expand mr-n1" data-target="pageMenu">
                        <em class="icon ti ti-menu"></em>
                    </a>

                    {* Add btn *}
                    <div class="toggle-expand-content" data-content="pageMenu">
                        <ul class="nk-block-tools g-3">
                            <li>
                                <a href="{url module=PostAdmin return=$smarty.server.REQUEST_URI}" class="btn btn-secondary">
                                    <em class="icon ti ti-circle-plus"></em>
                                    <span>Создать запись</span>
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {* List *}
    <div class="nk-block">
        <div class="card card-bordered card-stretch">
            <div class="card-inner-group">

                {* Filters *}
                <div class="card-inner">
                    <div class="card-title-group">

                        {* Title *}
                        <div class="card-title">
                            <h5 class="title">
                                {if !empty($keyword) && $posts_count}
                                    По вашему запросу <span class="text-soft">{$keyword}</span> найдено {$posts_count|plural:'запись':'записей':'записи'}
                                {elseif $posts_count}
                                    Всего {$posts_count|plural:'запись':'записей':'записи'}
                                {else}
                                    Нет записей
                                {/if}
                            </h5>
                        </div>

                        {* Buttons *}
                        <div class="card-tools mr-n1">
                            <ul class="btn-toolbar gx-1">

                                {* Search *}
                                {if $posts || $keyword}
                                <li>
                                    <a href="#" class="search-toggle toggle-search btn btn-icon" data-target="search">
                                        <em class="icon ti ti-search"></em>
                                    </a>
                                </li>
                                {if !empty($keyword)}
                                <li>
                                    <a href="#" class="btn btn-icon js-list-search-reset" data-toggle="tooltip" data-placement="top" data-original-title="Сбросить поиск">
                                        <em class="icon ti ti-x"></em>
                                    </a>
                                </li>
                                {/if}
                                {/if}

                            </ul>
                        </div>

                        {* Search *}
                        {if $posts || $keyword}
                        <div class="card-search search-wrap" data-search="search">
                            <div class="search-content">
                                <a href="#" class="search-back btn btn-icon toggle-search" data-target="search">
                                    <em class="icon ti ti-arrow-left"></em>
                                </a>
                                <form class="js-list-search" method="get">
                                    <input type="hidden" name="module" value="BlogAdmin">
                                    <input type="text" name="keyword" value="{$keyword|escape}" class="form-control border-transparent form-focus-none" placeholder="Поиск по заголовку или тексту..">
                                    <button class="search-submit btn btn-icon"><em class="icon ti ti-search"></em></button>
                                </form>
                            </div>
                        </div>
                        {/if}

                    </div>
                </div>

                {* List *}
                {if $posts}
                <form class="js-list-form" method="post">
                    <div class="card-inner p-0">

                        {* Head list *}
                        <div class="nk-tb-list nk-tb-ulist">
                            <div class="nk-tb-item nk-tb-head">
                                <div class="d-table w-100 table-fixed">
                                    <div class="nk-tb-col nk-tb-col-check">
                                        <div class="custom-control custom-control-sm custom-checkbox notext">
                                            <input type="checkbox" class="custom-control-input js-check-all" id="checkall">
                                            <label class="custom-control-label" for="checkall"></label>
                                        </div>
                                    </div>
                                    <div class="nk-tb-col">
                                        <span class="sub-text">Имя</span>
                                    </div>
                                    <div class="nk-tb-col tb-col-md w-150px">
                                        <span class="sub-text">Дата публикации</span>
                                    </div>
                                    <div class="nk-tb-col tb-col-xl">
                                        <span class="sub-text">URL</span>
                                    </div>
                                    <div class="nk-tb-col nk-tb-col-tools text-right">Действие</div>
                                </div>
                            </div>
                        </div>

                        {* Main list *}
                        <div class="nk-tb-list nk-tb-ulist nk-tb-slist is-compact js-list">

                            {* Posts *}
                            {foreach $posts as $post}
                            <div class="nk-tb-item js-list-item {if !$post->visible}invisible{/if}">
                                <div class="d-table w-100 table-fixed">

                                    {* Checkbox *}
                                    <div class="nk-tb-col nk-tb-col-check">
                                        <div class="custom-control custom-control-sm custom-checkbox notext">
                                            <input type="checkbox" name="check[]" value="{$post->id}" class="custom-control-input" id="uid_{$post->id}">
                                            <label class="custom-control-label" for="uid_{$post->id}"></label>
                                        </div>
                                    </div>

                                    {* Name *}
                                    <div class="nk-tb-col">
                                        <div class="user-card">
                                            <div class="user-avatar border bg-white rounded-pill rounded-0">
                                                <a href="{url module=PostAdmin id=$post->id return=$smarty.server.REQUEST_URI}">
                                                    <img src="{$post->image|resize:70:70:crop:blob}" class="rounded-0 p-1">
                                                </a>
                                            </div>
                                            <div class="user-info">
                                                <span class="tb-lead">
                                                    <a href="{url module=PostAdmin id=$post->id return=$smarty.server.REQUEST_URI}" class="text-secondary">{$post->name}</a>
                                                </span>
                                            </div>
                                        </div>
                                    </div>

                                    {* Date *}
                                    <div class="nk-tb-col tb-col-md w-150px">
                                        <div class="timeline">
                                            <div class="time">{$post->date|date}</div>
                                        </div>
                                    </div>

                                    {* URL *}
                                    <div class="nk-tb-col tb-col-xl">
                                        <span class="tb-sub">
                                            <span>/blog/{$post->url}</span>
                                        </span>
                                    </div>

                                    {* Tools *}
                                    <div class="nk-tb-col nk-tb-col-tools">
                                        <ul class="nk-tb-actions gx-1">

                                            {* Preview *}
                                            <li>
                                                <a href="/blog/{$post->url}" target="_blank" class="btn btn-trigger btn-icon" data-toggle="tooltip" data-placement="top" data-original-title="Открыть на сайте">
                                                    <em class="icon ti ti-external-link"></em>
                                                </a>
                                            </li>

                                            {* Active *}
                                            <li>
                                                <button type="button" class="btn btn-trigger btn-icon js-list-mark" data-mark-object="blog" data-mark-type="visible" data-mark-toogle-class="invisible" data-toggle="tooltip" data-placement="top" data-original-title="Активность">
                                                    <em class="icon ti ti-eye"></em>
                                                </button>
                                            </li>

                                            {* Delete *}
                                            <li>
                                                <button type="button" class="btn btn-trigger btn-icon text-danger js-list-delete" data-toggle="tooltip" data-placement="top" title="Удалить">
                                                    <em class="icon ti ti-trash"></em>
                                                </button>
                                            </li>

                                        </ul>
                                    </div>
                                </div>
                            </div>
                            {/foreach}

                        </div>
                    </div>

                    {* Pagination *}
                    <div class="card-inner">
                        <div class="nk-block-between-md g-3">

                            {* Mass actions *}
                            <div class="g">
                                <div class="center form-inline flex-nowrap gx-3">
                                    <div class="form-wrap w-200px">
                                        <select name="action" class="form-select form-select-sm" data-placeholder="Массовые действия">
                                            <option value="">Массовые действия</option>
                                            <option value="enable">Сделать активным</option>
                                            <option value="disable">Сделать неактивным</option>
                                            <option value="delete">Удалить</option>
                                        </select>
                                    </div>
                                    <div class="btn-wrap">
                                        <span class="d-none d-md-block">
                                            <button type="submit" class="btn btn-dim btn-outline-light">Применить</button>
                                        </span>
                                        <span class="d-md-none">
                                            <button type="submit" class="btn btn-dim btn-outline-light btn-icon">
                                                <em class="icon ti ti-arrow-right"></em>
                                            </button>
                                        </span>
                                    </div>
                                </div>
                            </div>

                            {* Pagination *}
                            <div class="g">
                                {include 'pagination.tpl' module='BlogAdmin'}
                            </div>

                        </div>
                    </div>
                </form>
                {else}
                <div class="card-inner">
                    <div class="nk-tb-item">
                        <p>Новости не найдены</p>
                    </div>
                </div>
                {/if}
            </div>
        </div>
    </div>

</div>
