{* Title *}
{if $file}
{$meta_title = "Файл $file" scope=root}
{else}
{$meta_title = "Файлы" scope=root}
{/if}

{* 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">
                	Файлы, тема - {$theme}
                </h3>
                <div class="nk-block-des text-soft">
                    <p>Онлайн редактор файлов дизайна.</p>
                </div>
            </div>

        </div>
    </div>

    {* 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 == 'permissions'}Установите права на запись для файла {$file}
            {else}{$message_error}{/if}.
    	</div>
    </div>
    {/if}

    {* Folders & Files *}
    <div class="nk-block-lg mb-3">

        <div class="card card-preview mb-2">
            <div class="card-inner">
                <nav>
                    <ul class="breadcrumb">
                        <li class="breadcrumb-item"><a href="{url module=DesignAdmin type=$module}">{$theme}</a></li>
						{assign var="dirs" value="/"|explode:$smarty.get.dir}
						{foreach $dirs as $dir}
						<li class="breadcrumb-item active">
							{if $dir@last}
								{$dir}
							{else}
								{* если вложенность дальше 2-ой, то надо дописывать урл :( *}
								<a href="{url module=DesignAdmin type=$module dir=$dir}">{$dir}</a>
							{/if}
						</li>
						{/foreach}
                    </ul>
                </nav>
            </div>
        </div>

		<div class="nk-block-head-xs">
            <div class="nk-block-between g-2">
                <div class="nk-block-head-content">
                    <h5 class="nk-block-title title">Список файлов</h5>
                </div>
            </div>
        </div>

        <div class="card card-preview">
            <div class="card-inner">
                {if $list->dirs || $list->files}

                {* Subfolders *}
				<div class="row no-gutters mx-1">
	                {foreach $list->dirs as $d}
                    <div class="col-2">
						<a href="{url module=DesignAdmin type=$module dir=$d}">
							<span class="nk-file-icon-type" style="width:30px;">
								<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 72">
                                    <g><rect x="32" y="16" width="28" height="15" rx="2.5" ry="2.5" style="fill:#f29611"></rect><path d="M59.7778,61H12.2222A6.4215,6.4215,0,0,1,6,54.3962V17.6038A6.4215,6.4215,0,0,1,12.2222,11H30.6977a4.6714,4.6714,0,0,1,4.1128,2.5644L38,24H59.7778A5.91,5.91,0,0,1,66,30V54.3962A6.4215,6.4215,0,0,1,59.7778,61Z" style="fill:#ffb32c"></path><path d="M8.015,59c2.169,2.3827,4.6976,2.0161,6.195,2H58.7806a6.2768,6.2768,0,0,0,5.2061-2Z" style="fill:#f2a222"></path></g>
                                </svg>
							</span>
							<span>
								{$d}
							</span>
						</a>
					</div>
	                {/foreach}
				</div>

                {* Subfiles *}
				<div class="row no-gutters mx-1">
	                {foreach $list->files as $t}
					<div class="col-2">
						<a class="nk-file-icon-link" href="{url module=DesignAdmin type=$module dir=$smarty.get.dir file=$t}">
							<span class="nk-file-icon-type" style="width:30px;">
								<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 72"><path d="M49,61H23a5.0147,5.0147,0,0,1-5-5V16a5.0147,5.0147,0,0,1,5-5H40.9091L54,22.1111V56A5.0147,5.0147,0,0,1,49,61Z" style="fill:#e3edfc"></path><path d="M54,22.1111H44.1818a3.3034,3.3034,0,0,1-3.2727-3.3333V11s1.8409.2083,6.9545,4.5833C52.8409,20.0972,54,22.1111,54,22.1111Z" style="fill:#b7d0ea"></path><path d="M19.03,59A4.9835,4.9835,0,0,0,23,61H49a4.9835,4.9835,0,0,0,3.97-2Z" style="fill:#c4dbf2"></path><rect x="27" y="31" width="18" height="2" rx="1" ry="1" style="fill:#7e95c4"></rect><rect x="27" y="35" width="18" height="2" rx="1" ry="1" style="fill:#7e95c4"></rect><rect x="27" y="39" width="18" height="2" rx="1" ry="1" style="fill:#7e95c4"></rect><rect x="27" y="43" width="14" height="2" rx="1" ry="1" style="fill:#7e95c4"></rect><rect x="27" y="47" width="8" height="2" rx="1" ry="1" style="fill:#7e95c4"></rect></svg>
							</span>
							<span>
								{if $file == $t}<b>{$t}</b>{else}{$t}{/if}
							</span>
						</a>
					</div>
					{/foreach}
				</div>
                {/if}

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

    {* Main block *}
	{if !empty($file_content)}
    <div class="nk-block">
    	<div class="card card-bordered">
			<div class="card-inner card-inner-xs">

				{* Head *}
				<div class="nk-block-head nk-block-head-lg pb-2">
					<div class="nk-block-between">

						{* Title *}
						<div class="nk-block-head-content">
							<h4 class="nk-block-title">
								{if $smarty.get.dir && !$file}
									Папка {$smarty.get.dir}, файл не выбран
								{elseif $smarty.get.dir && $file}
									Папка {$smarty.get.dir}, файл {$file}
								{elseif $file}
									Файл {$file}
								{else}
									Файл не выбран
								{/if}
							</h4>
							<div class="nk-block-des">
								<p>
                                    Выберите файл для редактирования из списка. Для быстрого сохранения можно использовать комбинацию клавиш CTRL+S.
								</p>
							</div>
						</div>

						{* Mobile toogle *}
						<div class="nk-block-head-content align-self-start d-lg-none">
							<a href="#" class="toggle btn btn-icon btn-trigger mt-n1" data-target="userAside">
								<em class="icon ti ti-menu"></em>
							</a>
						</div>
					</div>
				</div>

				{* Editor *}
				{if !empty($file)}
				<div class="nk-block">
					<form>
    					<div class="nk-data">
    						<div class="template-editor mw-100">
    							<div class="form-group">
    								<textarea name="file_content" class="form-control htmltext">{$file_content|escape}</textarea>
    							</div>
								<button type="button" class="btn btn-success js-design-save" data-dir="{$smarty.get.dir}" data-module="{$module}" data-filename="{$file}">Сохранить</button>
    						</div>
    					</div>
    				</form>
				</div>
				{/if}

			</div>
    	</div>
    </div>
	{/if}
</div>
