{* Title *}
{if $post->id}
{$meta_title = $post->name scope=root}
{else}
{$meta_title = 'Новая запись' scope=root}
{/if}

{* Tabs *}
{$tabs = "tabs" scope=root}

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

    {* Head *}
    <div class="nk-block-head nk-block-head-sm">
        <div class="nk-block-between">

            {* Title *}
            <div class="nk-block-head-content">
                <h3 class="nk-block-title page-title">
                    {if $post->id}
                        Редактирование записи: {$post->name}
                    {else}
                        Новый пост
                    {/if}
                </h3>
                <div class="nk-block-des text-soft">
                    <p>Управление записями магазина.</p>
                </div>
            </div>

            {* Buttons *}
            <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>

                    {* Buttons *}
                    <div class="toggle-expand-content" data-content="pageMenu">
                        <ul class="nk-block-tools g-3">

                            {* Return *}
                            {if $smarty.get.return}
                            <li>
                                <a href="{$smarty.get.return}" class="btn btn-white btn-outline-light">
                                    <em class="icon ti ti-arrow-back-up"></em>
                                    <span>Вернуться</span>
                                </a>
                            </li>
                            {/if}

                            {* Add one more *}
                            {if $post->id}
                            <li>
                                <a href="{url module=PostAdmin return=$smarty.server.REQUEST_URI}" class="btn btn-light btn-icon btn-outline-light" data-toggle="tooltip" data-placement="top" title="Создать запись">
                                    <em class="icon ti ti-plus"></em>
                                </a>
                            </li>

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

                        </ul>
                    </div>
                </div>
            </div>

        </div>
    </div>

    {* Success *}
    {if $smarty.get.message_success}
    <div class="pb-2">
        <div class="alert alert-fill alert-success alert-icon">
            <em class="icon ti ti-circle-check"></em>
            {if $smarty.get.message_success == 'added'}Запись добавлена{elseif $smarty.get.message_success == 'updated'}Запись обновлена{/if}.
        </div>
    </div>
    {/if}

    {* Error *}
    {if $smarty.get.message_error}
    <div class="pb-2">
        <div class="alert alert-fill alert-danger alert-icon">
            <em class="icon ti ti-circle-x"></em>
            {if $smarty.get.message_error == 'url_exists'}Запись с таким адресом уже существует{/if}.
        </div>
    </div>
    {/if}


    {* Form *}
    <form method="post">
        <input name="id" type="hidden" value="{$post->id}"/>

        <div class="row">

            {* Left side *}
            <div class="col-lg-8 mb-3 mb-lg-0">

                {* General *}
                <div class="card card-bordered mb-3">
                    <div class="card-content">
                        <div class="card-inner">
                            <div class="nk-block">
                            	<div class="nk-block-head">
                            		<h5 class="title">Основная информация</h5>
                            		<p>Основные данные записи.</p>
                            	</div>
                                <div class="row gy-4">
                                    <div class="col-sm-6">
                                        <div class="form-group">
                                            <label class="form-label" for="page_name">Название поста</label>
                                            <div class="form-control-wrap">
                                                <input type="text" class="form-control" id="page_name" name="name" value="{$post->name|escape}" required>
                                            </div>
                                            <span class="form-note">Например: "Самые красивые места Алтая".</span>
                                        </div>
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="form-group">
                                            <label class="form-label" for="tags">Теги, через запятую</label>
                                            <div class="form-control-wrap">
                                                <input type="text" class="form-control" id="tags" name="tags" value="{$post->tags|escape}">
                                            </div>
                                            <span class="form-note">Наример: "Природа,Здоровье,Наука".</span>
                                        </div>
                                    </div>
                                    <div class="col-md-4 col-sm-6">
                                        <div class="form-group">
                                            <label class="form-label" for="author">Автор</label>
                                            <div class="form-control-wrap">
                                                <input type="text" class="form-control" id="author" name="author" value="{$post->author|escape}" required>
                                            </div>
                                            <span class="form-note">Например: "Админ".</span>
                                        </div>
                                    </div>
                                    <div class="col-md-8 col-sm-6">
                                        <div class="form-group">
                                            <label class="form-label" for="category">Категории</label>
                                            <div class="form-control-wrap">
                                                {foreach $categories AS $url => $name}
                                                <div class="custom-control custom-switch mr-4">
                                                    <input class="custom-control-input" name="categories[]" type="checkbox" id="{$url}" value="{$url}" {if $url|in_array:$post->categories}checked{/if}>
                                                    <label class="custom-control-label" for="{$url}">{$name}</label>
                                                </div>
                                                {/foreach}
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="justify-center mt-2">
                                <button type="submit" class="btn btn-success">Сохранить</button>
                            </div>
                        </div>
                    </div>
                </div>

                {* Description *}
                <div class="card card-bordered mb-3">
                    <div class="card-content">
                        <div class="card-inner">
                            <div class="nk-block">
                            	<div class="nk-block-head">
                            		<h5 class="title">Описание</h5>
                            		<p>Краткое и полное описание поста.</p>
                            	</div>
                                {include "components/annotation-body.tpl" item=$post type="PostAdmin"}
                            </div>
                            <div class="justify-center mt-2">
                                <button type="submit" class="btn btn-success">Сохранить</button>
                            </div>
                        </div>
                    </div>
                </div>

                {* Images *}
                <div class="card card-bordered mb-3">
                    <div class="card-content">
                        <div class="card-inner">
                            {include "components/images.tpl" images=$post->images dir='pages'}
                        </div>
                    </div>
                </div>
            </div>

            {* Right side *}
            <div class="col-lg-4 card-box-right">
                <div class="card-box_sticky">
                    {* Params component *}
                    <div class="card card-bordered mb-3">
                        <div class="card-content">
                            <div class="card-inner">

                                <div class="nk-block">
                                    <div class="nk-block-head">
                                        <h5 class="title">Параметры</h5>
                                    </div>
                                    <div class="form-group">
                                        <label class="form-label" for="post_visible">Активность</label>
                                        <span class="form-note">Включение или отключение записи.</span>
                                        <div class="form-control-wrap">
                                            <div class="custom-control custom-switch">
                                                <input type="checkbox" name="visible" value="1" class="custom-control-input" id="post_visible" {if $post->visible}checked{/if}>
                                                <label class="custom-control-label" for="post_visible"></label>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>

                    {* Meta component *}
                    <div class="card card-bordered mb-3">
                        <div class="card-content">
                            <div class="card-inner">
                                {include "components/meta.tpl" item=$post url='/blog/'}
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </form>

</div>
