{*
* 2007-2024 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author    PrestaShop SA <contact@prestashop.com>
*  @copyright 2007-2024 PrestaShop SA
*  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*}
{extends file='module:agilemultisellerpro/views/templates/front/layouts/selleraccount.tpl'}

{block name='page_content'}
	{if isset($isSeller) AND $isSeller}
		<div>
			<div class="col-sm-2 ag-mt-10 ag-mb-10">
				<a class="btn btn-primary"
					href="{$link->getModuleLink('agilemultisellerpro', 'sellerproductdetail', ['id_product' =>0], true)|escape:'htmlall':'UTF-8'}">
					<i class="icon-plus-sign"></i>&nbsp;{l s='Add Product' d='Modules.Agilemultisellerpro.Products'}
				</a>
			</div>
		</div>

		<div class="table-responsive">
			<table class="table agile-table">
				<thead>
					<tr>
						<th class="first_item"><input class="form-control" type="checkbox" name="chkAll" id="chkAll" value="all"></th>

						<th class="item pl-0 pr-0" style="max-width: 50px;">
							{l s='ID' d='Modules.Agilemultisellerpro.Products'}
							<a href="javascript:void(0)"
								class="agile-products-sort {if $orderBy=='p.id_product' && $orderWay=='ASC'}current{/if}"
								onclick="orderByWay('p.id_product', 'ASC')"><i class="icon-caret-up"></i></a>
							<a href="javascript:void(0)"
								class="agile-products-sort {if $orderBy=='p.id_product' && $orderWay=='DESC'}current{/if}"
								onclick="orderByWay('p.id_product', 'DESC')"><i class="icon-caret-down"></i></a>
						</th>

						<th class="item">{l s='Photo' d='Modules.Agilemultisellerpro.Products'}</th>

						<th class="item">
							{l s='Name' d='Modules.Agilemultisellerpro.Products'}
							<a href="javascript:void(0)"
								class="agile-products-sort {if $orderBy=='pl.name' && $orderWay=='ASC'}current{/if}"
								onclick="orderByWay('pl.name', 'ASC')"><i class="icon-caret-up"></i></a>
							<a href="javascript:void(0)"
								class="agile-products-sort {if $orderBy=='pl.name' && $orderWay=='DESC'}current{/if}"
								onclick="orderByWay('pl.name', 'DESC')"><i class="icon-caret-down"></i></a>
						</th>

						<th class="item">
							{l s='Category' d='Modules.Agilemultisellerpro.Products'}
							<a href="javascript:void(0)"
								class="agile-products-sort {if $orderBy=='cl.name' && $orderWay=='ASC'}current{/if}"
								onclick="orderByWay('cl.name', 'ASC')"><i class="icon-caret-up"></i></a>
							<a href="javascript:void(0)"
								class="agile-products-sort {if $orderBy=='cl.name' && $orderWay=='DESC'}current{/if}"
								onclick="orderByWay('cl.name', 'DESC')"><i class="icon-caret-down"></i></a>
						</th>

						<th class="item">
							{l s='Price' d='Modules.Agilemultisellerpro.Products'}
							<a href="javascript:void(0)"
								class="agile-products-sort {if $orderBy=='p.price' && $orderWay=='ASC'}current{/if}"
								onclick="orderByWay('p.price', 'ASC')"><i class="icon-caret-up"></i></a>
							<a href="javascript:void(0)"
								class="agile-products-sort {if $orderBy=='p.price' && $orderWay=='DESC'}current{/if}"
								onclick="orderByWay('p.price', 'DESC')"><i class="icon-caret-down"></i></a>
						</th>

						<th class="item">
							{l s='Qty' d='Modules.Agilemultisellerpro.Products'}
							<a href="javascript:void(0)"
								class="agile-products-sort {if $orderBy=='sav.quantity' && $orderWay=='ASC'}current{/if}"
								onclick="orderByWay('sav.quantity', 'ASC')"><i class="icon-caret-up"></i></a>
							<a href="javascript:void(0)"
								class="agile-products-sort {if $orderBy=='sav.quantity' && $orderWay=='DESC'}current{/if}"
								onclick="orderByWay('sav.quantity', 'DESC')"><i class="icon-caret-down"></i></a>
						</th>

						<th class="item">
							<div class="text-nowrap">
								{l s='Active' d='Modules.Agilemultisellerpro.Products'}
								<a href="javascript:void(0)"
									class="agile-products-sort {if $orderBy=='p.active' && $orderWay=='ASC'}current{/if}"
									onclick="orderByWay('p.active', 'ASC')"><i class="icon-caret-up"></i></a>
								<a href="javascript:void(0)"
									class="agile-products-sort {if $orderBy=='p.active' && $orderWay=='DESC'}current{/if}"
									onclick="orderByWay('p.active', 'DESC')"><i class="icon-caret-down"></i></a>
							</div>
						</th>

						{if $is_apprpved_required}
							<th class="item">
								{l s='Approved' d='Modules.Agilemultisellerpro.Products'}
								<a href="javascript:void(0)"
									class="agile-products-sort {if $orderBy=='po.approved' && $orderWay=='ASC'}current{/if}"
									onclick="orderByWay('po.approved', 'ASC')"><i class="icon-caret-up"></i></a>
								<a href="javascript:void(0)"
									class="agile-products-sort {if $orderBy=='po.approved' && $orderWay=='DESC'}current{/if}"
									onclick="orderByWay('po.approved', 'DESC')"><i class="icon-caret-down"></i></a>
							</th>
						{/if}

						<th class="item text-xs-center">
							{l s='Date' d='Modules.Agilemultisellerpro.Products'}
							<a href="javascript:void(0)"
								class="agile-products-sort {if $orderBy=='p.date_add' && $orderWay=='ASC'}current{/if}"
								onclick="orderByWay('p.date_add', 'ASC')"><i class="icon-caret-up"></i></a>
							<a href="javascript:void(0)"
								class="agile-products-sort {if $orderBy=='p.date_add' && $orderWay=='DESC'}current{/if}"
								onclick="orderByWay('p.date_add', 'DESC')"><i class="icon-caret-down"></i></a>
						</th>

						<th class="last_item">
							<input type="button" class="btn btn-primary btn-sm" name="export" value="Export" id="product_export"
								onclick="CSVOnClick()" />
						</th>
					</tr>

					<tr class="agile-table-filter">
						<th>{*Checkbox*}</th>

						<th class="align-middle pl-0 pr-0" style="max-width: 50px;">
							<input type="number" step="1" min="1" class="form-control agile-padding-lr4" name="filter_id_product"
								id="filter_id_product" value="{$filter_id_product|escape:'htmlall':'UTF-8'}">
						</th>

						<th>{*Photo*}</th>

						<th class="align-middle">
							<input type="text" class="form-control agile-padding-lr4" name="filter_name" id="filter_name"
								value="{$filter_name|escape:'htmlall':'UTF-8'}">
						</th>

						<th class="align-middle">
							<input type="text" class="form-control agile-padding-lr4" name="filter_category" id="filter_category"
								value="{$filter_category|escape:'htmlall':'UTF-8'}">
						</th>

						<th class="align-middle">
							<input type="number" min="1" step="any" class="form-control agile-padding-lr4" name="filter_price"
								id="filter_price" value="{$filter_price|escape:'htmlall':'UTF-8'}">
						</th>

						<th class="align-middle">
							<input type="number" step="1" min="1" class="form-control agile-padding-lr4" name="filter_quantity"
								id="filter_quantity" value="{$filter_quantity|escape:'htmlall':'UTF-8'}">
						</th>

						<th class="align-middle agile-filter-active">
							<select class="form-control agile-padding-lr4" name="filter_active" id="filter_active">
								<option value="" {if strlen($filter_active)==0}selected{/if}></option>
								<option value="1" {if $filter_active=="1"}selected{/if}>{l s='Yes' d='Modules.Agilemultisellerpro.Products'}
								</option>
								<option value="0" {if strlen($filter_active)>0 && $filter_active=="0"}selected{/if}>
									{l s='No' d='Modules.Agilemultisellerpro.Products'}</option>
							</select>
						</th>

						{if $is_apprpved_required}
							<th class="align-middle">
								<select class="form-control agile-padding-lr4" name="filter_approved" id="filter_approved">
									<option value="" {if strlen($filter_approved)==0}selected{/if}></option>
									<option value="1" {if $filter_approved=="1"}selected{/if}>
										{l s='Yes' d='Modules.Agilemultisellerpro.Products'}
									</option>
									<option value="0" {if strlen($filter_approved)>0 && $filter_approved=="0"}selected{/if}>
										{l s='No' d='Modules.Agilemultisellerpro.Products'}</option>
								</select>
							</th>
						{/if}

						<th class="align-middle agile-filter-date">
							<div class="col-md-6 ag-pl-5 ag-pr-5">
								<input class="form-control btn-block agile-padding-lr4" type="date" id="filter_date_add_from"
									name="filter_date_add_from" value="{$filter_date_add_from|escape:'htmlall':'UTF-8'}" maxlength="10"
									autocomplete="off" />
							</div>

							<div class="col-md-6 ag-pl-5 ag-pr-5">
								<input class="form-control btn-block agile-padding-lr4" type="date" id="filter_date_add_to"
									name="filter_date_add_to" value="{$filter_date_add_to|escape:'htmlall':'UTF-8'}" maxlength="10"
									autocomplete="off" />
							</div>
						</th>

						<th class="align-middle agile-filter-action">
							<div class="col-md-6 ag-pl-5 ag-pr-5">
								<button type="button" class="btn btn-primary btn-block agile-padding-lr4" name="btnGo" onclick="goOnClick()"
									title="{l s='Search' d='Modules.Agilemultisellerpro.Products'}">
									<i class="material-icons mr-0" aria-hidden="true">search</i>
								</button>
							</div>

							<div class="col-md-6 ag-pl-5 ag-pr-5">
								<button type="button" class="btn btn-warning btn-block agile-padding-lr4" name="reset" id="reset"
									onclick="document.location='{$link->getModuleLink('agilemultisellerpro', 'sellerproducts', [],true)|escape:'htmlall':'UTF-8'}'"
									title="{l s='Reset' d='Modules.Agilemultisellerpro.Products'}">
									<i class="material-icons" aria-hidden="true">clear</i>
								</button>
							</div>
						</th>
					</tr>
				</thead>

				<tbody>
					{foreach from=$products item=product name=myLoop}
						{assign var='detail_url' value=$link->getModuleLink('agilemultisellerpro', 'sellerproductdetail', ['id_product' => $product.id_product], true)}
						<tr
							class="{if $smarty.foreach.myLoop.first}first_item{elseif $smarty.foreach.myLoop.last}last_item{else}item{/if} {if $smarty.foreach.myLoop.index % 2}alternate_item{/if}">
							<td class="pointer left align-middle"><input class="form-control" type="checkbox" name="chkProd_{$product.id_product|intval}"
									id="chkProd_{$product.id_product|intval}" value="{$product.id_product|intval}"></td>
							<td class="pointer left align-middle">
								<a class="color-myaccount" href="{$detail_url|escape:'htmlall':'UTF-8'}">{$product.id_product|intval}</a>
							</td>
							<td class="pointer left align-middle" onclick="document.location = '{$detail_url|escape:'htmlall':'UTF-8'}'">
								<a href="{$detail_url|escape:'htmlall':'UTF-8'}">
									{if $product.cover}
										<img class="img-thumbnail" src="{$product.cover.small.url|escape:'htmlall':'UTF-8'}" />
									{else}
										<img class="img-thumbnail"
											src="{$urls['no_picture_image']['small']['url']|escape:'htmlall':'UTF-8'}" />
									{/if}
								</a>
							</td>
							<td class="pointer left align-middle"><a href="{$detail_url|escape:'htmlall':'UTF-8'}">{$product.name|escape:'htmlall':'UTF-8'}</a></td>
							<td class="pointer left align-middle">{$product.category_name|escape:'htmlall':'UTF-8'}</td>
							<td class="pointer right align-middle">
								{* <span class="price">{$product.price}</span> *}
								<span>{$product.default_price|escape:'htmlall':'UTF-8'} {l s='(tax excl.)' d='Modules.Agilemultisellerpro.Products'}</span>
							</td>
							<td class="pointer text-xs-center align-middle">{$product.quantity|escape:'htmlall':'UTF-8'}</td>
							<td class="text-xs-center align-middle">
								{if $product.active == 1}
									<a class="ag-cur-pointer" onclick="actionOnProduct('inactive', {$product.id_product|intval})">
										<i class="material-icons btn-outline-success" aria-hidden="true">done</i>
									</a>
								{else}
									<a class="ag-cur-pointer" onclick="actionOnProduct('active', {$product.id_product|intval})">
										<i class="material-icons btn-outline-danger" aria-hidden="true">close</i>
									</a>
								{/if}
							</td>
							{if $is_apprpved_required}
								<td class="text-xs-center align-middle" valign="middle">
									{if $product.approved == 1}
										<i class="material-icons btn-outline-success" aria-hidden="true">done</i>
									{else}
										<i class="material-icons btn-outline-danger" aria-hidden="true">close</i>
									{/if}
								</td>
							{/if}
							<td class="align-middle text-xs-center">
								{Tools::displayDate($product.date_add, true)|escape:'htmlall':'UTF-8'}
							</td>
							<td class="text-xs-center align-middle">
								<a class="ag-cur-pointer" onclick="onClickConfirm('delete',{$product.id_product|intval})">
									<i class="material-icons btn-outline-danger" aria-hidden="true">delete</i>
								</a>
								<a class="ag-cur-pointer" onclick="onClickConfirm('duplicate',{$product.id_product|intval})">
									<i class="material-icons btn-outline-primary" aria-hidden="true">content_copy</i>
								</a>
							</td>
						</tr>
					{/foreach}
					{if $numOfProducts == 0}
						<tr>
							<td colspan="10">
								<p class="alert alert-warning">
									{l s='You have no products, create a new one' d='Modules.Agilemultisellerpro.Products'}
								</p>
							</td>
						</tr>
					{elseif count($products) < 1}
						<tr>
							<td colspan="10">
								<p class="alert alert-warning">
									{l s='You do not have any products meet your search criteria' d='Modules.Agilemultisellerpro.Products'}
								</p>
							</td>
						</tr>
					{/if}
				</tbody>
			</table>
		</div>
		{if count($products) > 0}
			<hr>
			<div class="row">
				<div class="col-md-3 col-sm-6 col-xs-12">
					<form
						action="{$link->getModuleLink('agilemultisellerpro', 'sellerproducts', ['orderBy'=>$orderBy,'orderWay'=>$orderWay], true)|escape:'htmlall':'UTF-8'}"
						id="frmBulkAction" method="post">
						<select class="form-control" name="bulkAction" id="bulkAction">
							<option value=""> -- Bulk Action --</option>
							<option value="delete">{l s='Delete' d='Modules.Agilemultisellerpro.Products'}</option>
							<option value="enable">{l s='Enable' d='Modules.Agilemultisellerpro.Products'}</option>
							<option value="disable">{l s='Disable' d='Modules.Agilemultisellerpro.Products'}</option>
						</select>
						<input type="hidden" name="bulkActionData" id="bulkActionData" value="[]">
					</form>
				</div>

			</div>
			<div class="row">
				<div class="col-md-12">
					{block name='pagination'}
						{include file='_partials/pagination.tpl' pagination=$pagination}
					{/block}
				</div>
			</div>
		{/if}
		<!-- agile -->
	{/if}

{/block}

{block name='javascript_bottom'}
	{$smarty.block.parent}

	<script type="text/javascript">
		var listurl = "{$link->getModuleLink('agilemultisellerpro', 'sellerproducts', [], true)|escape:'htmlall':'UTF-8'}";
		var allowCopyMainStoreProduct = {$allowCopyMainStoreProduct|intval};
		var n = {$n|intval};
		var p = {$p|intval};
		var orderBy = "{$orderBy|escape:'htmlall':'UTF-8'}";
		var orderWay = "{$orderWay|escape:'htmlall':'UTF-8'}";
		var msgDelete = "{$msgDelete|escape:'htmlall':'UTF-8'}";
		var msgDuplicate = "{$msgDuplicate|escape:'htmlall':'UTF-8'}";
		var duplicateURL = "{$link->getModuleLink('agilemultisellerpro', 'sellerproducts', ['process' => 'duplicate'], true)|escape:'htmlall':'UTF-8'}";
		var bulkmsg_delete = "{l s='Are you sure want proceed to delete selected items?' d='Modules.Agilemultisellerpro.Products'}";
		var bulkmsg_enable = "{l s='Are you sure want proceed to enable selected items?' d='Modules.Agilemultisellerpro.Products'}";
		var bulkmsg_disable = "{l s='Are you sure want proceed to disable selected items?' d='Modules.Agilemultisellerpro.Products'}";
	</script>
{/block}
