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

            {if $message_error != 'no_permission'}
            <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>

                    {* Form *}
                    <form class="js-backup-form" method="post">
                    	<input type="hidden" name="name" value="">
                    	<input type="hidden" name="action" value="">
                    </form>

                    {* Add btn *}
                    <div class="toggle-expand-content" data-content="pageMenu">
                        <ul class="nk-block-tools g-3">
                            <li>
                                <button type="button" class="btn btn-secondary js-backup-create">
                                    <em class="icon ti ti-circle-plus"></em>
                                    <span>Создать бекап</span>
                                </button>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            {/if}

        </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 == 'created'}Бекап создан{elseif $smarty.get.message_success == 'deleted'}Файл удален{elseif $smarty.get.message_success == 'unzipped'}Фото восстановлены{elseif $smarty.get.message_success == 'restored'}Бекап восстановлен{/if}.
    	</div>
    </div>
    {/if}

    {* Error *}
    {if $message_error}
    <div class="pb-2">
    	<div class="alert alert-fill alert-danger alert-icon">
    		<em class="icon ti ti-circle-x"></em>
    		{if $message_error == 'no_permission'}Установить права на запись в папку {$backup_files_dir}{else}{$message_error}{/if}.
    	</div>
    </div>
    {/if}

    {* List *}
    {if $message_error != 'no_permission'}
    <div class="nk-block">
        <div class="card card-bordered card-stretch">
            <div class="card-inner-group">

                {if $backups}
                <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">

                                {* Check all *}
                                <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">
                                    <span class="sub-text">Размер</span>
                                </div>
                                <div class="nk-tb-col nk-tb-col-tools text-right">Действие</div>
                            </div>
                        </div>

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

                            {* Payments *}
                            {foreach from=$backups item=backup key=key}
                            <div class="nk-tb-item js-list-item">

                                {* 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="{$backup->name}" class="custom-control-input" id="uid_{$key}">
                                        <label class="custom-control-label" for="uid_{$key}"></label>
                                    </div>
                                </div>

                                {* Header *}
                                <div class="nk-tb-col ">
                                    <a href="/admin/backup/{$backup->name}" target="_blank">
                                        <span class="tb-lead">
                                            {$backup->name}
                                        </span>
                                    </a>
                                </div>

                                {* Size *}
                                <div class="nk-tb-col tb-col-md">
                                	<span class="sub-text">{if $backup->size>1024*1024}{($backup->size/1024/1024)|round:2} MB{else}{($backup->size/1024)|round:2} KB{/if}
                                    </span>
                                </div>

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

                                        {* Restore *}
                                        <li>
                                            <a href="#" class="btn btn-trigger btn-icon js-backup-restore" data-file="{$backup->name}" data-toggle="tooltip" data-placement="top" title="" data-original-title="Восстановить бекап">
                                                <em class="icon ti ti-database"></em>
                                            </a>
                                        </li>

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

                                    </ul>
                                </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="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>

                        </div>
                    </div>
                </form>
                {else}
                <div class="card-inner">
                    <div class="nk-tb-item">
                        <p>Бекапы не найдены.</p>
                    </div>
                </div>
                {/if}
            </div>
        </div>
    </div>
    {/if}

</div>
