
	<!-- Page header -->
	{capture name="buttons"}
{*	    {if !empty($sections)}*}
			<a class="btn btn-sm btn-primary" data-bs-popup="tooltip" title="{general:add}" data-bs-placement="auto" href="{$adminUrl}/product?action=edit{if isset($page)}&page={$page}{/if}{$buildQueryString}"><i class="icon-plus3"></i></a>
{*	    {/if}*}
	{/capture}

	{capture name="breadcrumb"}
		<a href="{$adminUrl}/products" class="breadcrumb-item">{$title}</a>
	{/capture}

	{capture name="showBy"}
	    {include file="module/show-by.tpl" url="{$adminUrl}/products"}
	{/capture}

	{include file="components/page-header.tpl" buttons=$smarty.capture.buttons breadcrumb=$smarty.capture.breadcrumb showBy=$smarty.capture.showBy}
	<!-- /page header -->


	<!-- Content area -->
	<div class="content">

	    <div class="row">
	        <div class="col-md-12">
	            {if empty($sections)}
				    <div class="card border shadow-sm">
					    <div class="alert bg-danger text-white alert-dismissible m-0">
						    <span class="font-weight-semibold">Перед добавлением продукции, добавьте хотя бы один <a href="{$adminUrl}/section?action=add&parentId=0" class="text-white">раздел</a> c типом продукция.</span>
					    </div>
				    </div>
	            {/if}
			    <div class="card border shadow-sm">
	                {include file="components/selectors.tpl" filter=true url="{$adminUrl}/products" filterDate=true}
			    </div>

	            <div class="card border shadow-sm">
		            <div class="">
		                <table class="table table-xs table-togglable table-striped table-hover" id="products">
		                    <thead id="header">
		                        <tr>
			                        <th data-hide="phone" class="text-center" width="30">
				                        <div class="form-check">
					                        <input type="checkbox" class="form-check-input content_check_all">
				                        </div>
			                        </th>
{*			                        <th class="text-center" width="80">{general:table:date}</th>*}
									<th class="text-center gridjs-th-sort main-th-col-sortable" onclick="tableSort(this, '{$module}'); return false;" data-sort-by="publishedOn" data-sort-order="{if isset($sortOrder.column) && $sortOrder.column eq 'publishedOn'}{if $sortOrder.sort eq 'asc'}desc{else}asc{/if}{else}asc{/if}" width="100">{general:table:date} <button class="gridjs-sort gridjs-sort-{if isset($sortOrder.column) && $sortOrder.column eq 'publishedOn'}{$sortOrder.sort}{else}neutral{/if}"></button></th>
		                            <th class="text-center" width="120">{general:table:image}</th>
									<th class="text-start gridjs-th-sort main-th-col-sortable" onclick="tableSort(this, '{$module}'); return false;" data-sort-by="title" data-sort-order="{if isset($sortOrder.column) && $sortOrder.column eq 'title'}{if $sortOrder.sort eq 'asc'}desc{else}asc{/if}{else}asc{/if}">{general:table:product} <button class="gridjs-sort gridjs-sort-{if isset($sortOrder.column) && $sortOrder.column eq 'title'}{$sortOrder.sort}{else}neutral{/if}"></button></th>
{*			                        <th class="text-end">{general:table:price}</th>*}
{*			                        <th class="text-center">{general:table:count}</th>*}
{*			                        <th class="text-center">Наличие</th>*}
									<th class="text-center gridjs-th-sort main-th-col-sortable" onclick="tableSort(this, '{$module}'); return false;" data-sort-by="sectionId" data-sort-order="{if isset($sortOrder.column) && $sortOrder.column eq 'sectionId'}{if $sortOrder.sort eq 'asc'}desc{else}asc{/if}{else}asc{/if}">{general:table:section} <button class="gridjs-sort gridjs-sort-{if isset($sortOrder.column) && $sortOrder.column eq 'sectionId'}{$sortOrder.sort}{else}neutral{/if}"></button></th>
		                            <th class="text-center text-muted" width="30"><i class="ph-check"></i></th>
		                        </tr>
		                    </thead>
		                    {if $products}
		                    <tbody>

		                        {foreach item=product from=$products name=products}
		                        <tr id="product-{$product.productId}" data-id="{$product.productId}" class="{if $product.status eq 'H'}table-danger{/if} {if $product.isFeatured}table-success{/if}">
			                        <td class="text-center">
				                        <div class="form-check">
					                        <input type="checkbox" class="form-check-input content_list_check" value="{$product.productId}" data-id="{$product.productId}">
				                        </div>
			                        </td>
			                        <td class="text-start text-nowrap"><span class="fw-normal">{$product.publishedOn|date_format:$config.date_format_custom}</span></td>
			                        <td class="text-center"><div class="preview preview-md"><img src="{$product.image}" class="img-thumbnail w-80px" alt="{$product.title}"/></div></td>

			                        <td class="text-start"><a class="fw-normal" href="{$product.url}" target="_blank">{$product.title|truncate:75}</a></td>
{*		                            <td class="text-end text-nowrap"><span class="fw-semibold">{$product.price|number_format:0:".":" "}</span> сум</td>*}
{*			                        <td class="text-center"><span class="badge bg-warning">{$product.quantity}</span></td>*}
{*			                        <td class="text-center"><span class="badge bg-secondary">{$product.stock_status}</span></td>*}
			                        <td class="text-center"><span class="fw-normal">{$product.section.name|truncate:25}</span></td>
		                            <td class="text-center">
		                                <div class="d-inline-flex">
			                                <a class="text-primary" data-bs-popup="tooltip" title="{general:edit}" data-bs-placement="auto" href="{$adminUrl}/product?action=edit&id={$product.productId}{if !empty($page)}&page={$page}{/if}{$buildQueryString}"><i class="ph-note-pencil me-2"></i></a>
		                                    <div class="dropdown">
			                                    <a class="text-body" data-bs-toggle="dropdown""><i class="ph-list"></i></a>

		                                        <div class="dropdown-menu dropdown-menu-end">
		                                            <a class="dropdown-item" href="{$adminUrl}/product?action=edit&id={$product.productId}{if isset($page)}&page={$page}{/if}{$buildQueryString}"><i class="ph-note-pencil me-2"></i>  {general:edit}</a>
		                                            <button class="dropdown-item ajax_action" data-module="products" data-action="status" data-id="{$product.productId}"><i class="{if $product.status eq 'V'}ph-eye{else}ph-eye-slash{/if} me-2"></i> {general:status}</button>
		                                            <div class="dropdown-divider"></div>
		                                            <button class="dropdown-item text-danger" href="javascript:void('');" onclick="newRemove({$product.productId}, '{$product.title nofilter}', 'products');"><i class="ph-trash me-2"></i> {general:delete}</button>
		                                        </div>
		                                    </div>
		                                </div>
		                            </td>
		                        </tr>
		                        {/foreach}
		                    </tbody>
		                {else}
		                    <tbody><tr class="odd"><td class="text-center" colspan="10">- {general:none} -</td></tr></tbody>
		                    {/if}
		                </table>
		            </div>
	                {include file="module/pagination.tpl" url="{$adminUrl}/products" params="{$buildQueryString}"}
	            </div>
	        </div>

		    <div class="card footer_navbar collapse bg-light m-0">
			    <form method="post" action="#">
				    <div class="card-footer bg-white d-flex justify-content-center align-items-center py-2">
					    <ul class="nav nav-pills mb-0">
						    <li class="nav-item px-2 wmin-sm-200">
							    <div class="form-group mb-0">
								    <select class="form-control select content_select_action" name="group_action" data-fouc>
									    <option value="">Выбрать действие</option>
	{*								    <option value="copy">Создать дубликат</option>*}
	{*								    <option value="section">Переместить в раздел</option>*}
									    <option value="status"> Изменить статус</option>
									    <option value="remove">Удалить выбранное</option>
								    </select>
							    </div>
						    </li>
						    <li class="nav-item px-2">
							    <button class="btn btn-sm btn-primary px-3 content_save_button" type="button">Применить</button>
						    </li>
					    </ul>
				    </div>
			    </form>
		    </div>

	    </div>

	</div>

	<script>
    $(document).ready(function () {
      
        {if isset($messages.saved)} new Noty({ text: '{products:messages:0}', type: 'success', timeout: 1500 }).show(); {/if}
        {if isset($errors.access_denied)} new Noty({ text: '{products:errors:0}', type: 'error', timeout: 2500 }).show(); {/if}
        {if isset($errors.not_saved)}   new Noty({ text: '{products:errors:3}', type: 'error', timeout: 2500 }).show(); {/if}
        {if isset($errors.no_sections)} new Noty({ text: '{products:errors:4}', type: 'error', timeout: 2500 }).show(); {/if}
        {if isset($errors.article_not_found)} new Noty({ text: '{products:errors:6}', type: 'error', timeout: 2500 }).show(); {/if}
    });
    
    function deleteMessage(){
        new Noty({ text: '{products:messages:2}', layout: 'topRight', type: 'success', timeout: 1500 }).show();
    }
    function successImageMessage(){
        new Noty({ text: '{sections:messages:10}', layout: 'topRight', type: 'success', timeout: 1500 }).show();
    }

    function notFound(){
        new Noty({ text: 'контент не найден или пустой ID', layout: 'topRight', type: 'error', timeout: 1500 }).show();
    }
    function approveError(){
        new Noty({ text: 'ошибка при одобрение контента', layout: 'topRight', type: 'error', timeout: 2500 }).show();
    }
    function statusError(){
        new Noty({ text: 'ошибка при изменение статуса контента', layout: 'topRight', type: 'error', timeout: 2500 }).show();
    }

    function approveSuccess(id) {
        document.getElementById('status-' + id).innerHTML = '{general:statuses:V}';
        document.getElementById('product-approve-' + id).style.display = 'none';
        document.getElementById('product-status-' + id).innerHTML = '<i class="icon-eye"></i> {general:statuses:V}';
        new Noty({ text: 'Контент одобрен без модерации', layout: 'topRight', type: 'success', timeout: 1500 }).show();
    }


    // Показать вариант
    $(document).on('click', 'a.expand_variant', function() {
        $(this).closest("td.cell").find("li.variant").fadeIn('fast');
        $(this).closest("td.cell").find("a.expand_variant").hide();
        $(this).closest("td.cell").find("a.roll_up_variant").show();
        return false;
    });

    // Свернуть вариант

    $(document).on('click', 'a.roll_up_variant', function() {
        $(this).closest("td.cell").find("li.variant").fadeOut('fast');
        $(this).closest("td.cell").find("a.roll_up_variant").hide();
        $(this).closest("td.cell").find("a.expand_variant").show();
        return false;
    });

    // выбрать все
    $(document).on("change", ".content_check_all", function () {
        if ($(this).is(":checked")) {
            $('.content_list_check').each(function () {
                if (!$(this).is(":checked")) $(this).trigger("click");
            });
            $('.footer_navbar').removeClass('collapse').addClass('fixed-bottom')
        } else {
            $('.content_list_check').each(function () {
                if ($(this).is(":checked")) $(this).trigger("click");
            });
            $('.footer_navbar').addClass('collapse').removeClass('fixed-bottom')
        }
    });

    // быбрать один
    $(document).on("change", ".content_list_check", function () {
        if ( $('input.content_list_check:checked').length > 0 ) {
            $('.footer_navbar').removeClass('collapse').addClass('fixed-bottom')

        } else {
            $('.footer_navbar').addClass('collapse').removeClass('fixed-bottom')
            if ($('.content_check_all').is(":checked")) $('.content_check_all').trigger("click");
            // $('.content_check_all').trigger("click");
        }
    });

    // $(document).ready(function () {
    $(document).on('click', '.content_save_button',  function () {
        var productIds = [];
        $('.content_list_check').each(function () {
            if ($(this).is(":checked")) {
                productIds.push($(this).attr("data-id"));
            }
        });

        var group_action_text =  $(".content_select_action :selected").text();
        var group_action =  $(".content_select_action").val();

        bootbox.confirm({
            message: 'Вы действительно хотите "'+group_action_text+'"? <br> action: => ' + group_action + ' <br>ids: => ' + productIds ,
            callback: function(result) {
                console.log(result);
                if (result === true) {
                    $.post('index.php?mod=products&action=group', { productIds: productIds, group_action: group_action }, function (data) {
                        console.log(data);
                        new Noty({ text: data.message, type: data.type }).show();
                        if (data.status === 200) {
                            setTimeout(function() {
                                window.location.reload();
                            }, 1500);

                        }
                    }, 'json');
                }
            }
        });
    });


	</script>



