{*
* 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
*}
{if isset($product->id)}
	<div id="product-quantities" class="panel product-tab">
		<h3>{l s='Available quantities for sale' d='Modules.Agilemultisellerpro.Product'}</h3>

		{if !$field.availableValues.ps_stock_management}
			<div class="alert alert-info">{l s='The stock management is disabled' d='Modules.Agilemultisellerpro.Product'}</div>
		{else}
			<div class="alert alert-info" style="display:none">
				{l s='This interface allows you to manage available quantities for sale for products. It also allows you to manage product combinations in the current shop.' d='Modules.Agilemultisellerpro.Product'}<br />
				{l s='You can choose whether or not to use the advanced stock management system for this product.' d='Modules.Agilemultisellerpro.Product'}<br />
				{l s='You can manually specify the quantities for the product/each product combination, or you can choose to automatically determine these quantities based on your stock (if advanced stock management is activated).' d='Modules.Agilemultisellerpro.Product'}<br />
				{l s='In this case, quantities correspond to the real-stock quantities in the warehouses connected with the current shop, or current group of shops.' d='Modules.Agilemultisellerpro.Product'}<br />
				{l s='For packs: If it has products that use advanced stock management, you have to specify a common warehouse for these products in the pack.' d='Modules.Agilemultisellerpro.Product'}<br />
				{l s='Also, please note that when a product has combinations, its default combination will be used in stock movements.' d='Modules.Agilemultisellerpro.Product'}
			</div>

			{if $field.availableValues.show_quantities == true}

				<div class="alert alert-info" style="display:none;" id="available_quantity_ajax_msg"></div>
				<div class="alert alert-danger" style="display:none;" id="available_quantity_ajax_error_msg"></div>
				<div class="alert alert-success" style="display:none;" id="available_quantity_ajax_success_msg"></div>

				<div class="form-group " {if $product->is_virtual || $product->cache_is_pack}style="display:none;"
					{else}style="display:none;"
					{/if} class="row stockForVirtualProduct">
					<label class="agile-col-md-3 agile-col-lg-3 agile-col-xl-3"></label>
					<div class="agile-col-md-9 agile-col-lg-9 agile-col-xl-9 ">
						<p class="checkbox">
							<label for="advanced_stock_management">
								<input type="checkbox" name="advanced_stock_management" class="advanced_stock_management"
									id="advanced_stock_management"
									{if $product->advanced_stock_management == 1 && $field.availableValues.stock_management_active == 1} value="1" checked="checked"
										{else} value="0" {/if} {if $field.availableValues.stock_management_active == 0 || $product->cache_is_pack} disabled="disabled"
									{/if} />
								{l s='I want to use the advanced stock management system for this product.' d='Modules.Agilemultisellerpro.Product'}
							</label>
						</p>
						{if $field.availableValues.stock_management_active == 0 && !$product->cache_is_pack}
							<p class="text-info"><i
									class="icon-info-sign"></i>&nbsp;{l s='This requires you to enable advanced stock management.' d='Modules.Agilemultisellerpro.Product'}
							</p>
						{else if $product->cache_is_pack}
							<p class="text-info">
								{l s='This parameter depends on the product(s) in the pack.' d='Modules.Agilemultisellerpro.Product'}</p>
						{/if}
					</div>
				</div>

				<div {if $product->is_virtual || $product->cache_is_pack}style="display:none;" {else}style="display:none;" {/if}
					class="row stockForVirtualProduct">
					<label class="control-label agile-col-md-3 agile-col-lg-3 agile-col-xl-3"
						for="depends_on_stock_1">{l s='Available quantities:' d='Modules.Agilemultisellerpro.Product'}</label>
					<div class="agile-col-md-9 agile-col-lg-9 agile-col-xl-9">
						<p class="radio">
							<label for="depends_on_stock_1">
								<input type="radio" name="depends_on_stock" class="depends_on_stock" id="depends_on_stock_1" value="1"
									{if $product->depends_on_stock == 1 && $field.availableValues.stock_management_active == 1} checked="checked" {/if}
									{if $field.availableValues.stock_management_active == 0 || $product->advanced_stock_management == 0 || $product->cache_is_pack}
									disabled="disabled" {/if} />
								{l s='Available quantities for current product and its combinations are based on warehouse stock. ' d='Modules.Agilemultisellerpro.Product'}
								{if ($field.availableValues.stock_management_active == 0 || $product->advanced_stock_management == 0) && !$product->cache_is_pack}
									&nbsp;-&nbsp;{l s='This requires you to enable advanced stock management globally or for this product.' d='Modules.Agilemultisellerpro.Product'}
								{else if $product->cache_is_pack}
									&nbsp;-&nbsp;{l s='This parameter depends on the product(s) in the pack.' d='Modules.Agilemultisellerpro.Product'}
								{/if}
							</label>
						</p>
						<p class="radio">
							<label for="depends_on_stock_0" for="depends_on_stock_0">
								<input type="radio" name="depends_on_stock" class="depends_on_stock" id="depends_on_stock_0" value="0"
									{if $product->depends_on_stock == 0 || $field.availableValues.stock_management_active == 0} checked="checked" {/if} />
								{l s='I want to specify available quantities manually.' d='Modules.Agilemultisellerpro.Product'}
							</label>
						</p>
					</div>
				</div>

				{if isset($field.availableValues.pack_quantity)}
					<div class="alert alert-info">
						<p>
							{l s='When a product has combinations, quantities will be based on the default combination.' d='Modules.Agilemultisellerpro.Product'}
						</p>
						<p>
							{l s='Given the quantities of the products in this pack, the maximum quantity should be:' d='Modules.Agilemultisellerpro.Product'}
							{$field.availableValues.pack_quantity|escape:'htmlall':'UTF-8'}</p>
					</div>
				{/if}

				<div class="form-group ">
					<div class="col-md-12">
						<table class="table">
							<thead>
								<tr>
									<th>{l s='Quantity' d='Modules.Agilemultisellerpro.Product'}</th>
									<th>{l s='Designation' d='Modules.Agilemultisellerpro.Product'}</th>
								</tr>
							</thead>
							{foreach from=$field.availableValues.attributes item=attribute}
								<tr>
									<td class="available_quantity" id="qty_{$attribute['id_product_attribute']|intval}">
										<input type="text" class="form-control col-md-6"
											value="{$field.availableValues.available_quantity[$attribute['id_product_attribute']]|escape:'htmlall':'UTF-8'}" />
									</td>
									<td>{$field.availableValues.product_designation[$attribute['id_product_attribute']]|escape:'htmlall':'UTF-8'}</td>
								</tr>
							{/foreach}
						</table>
					</div>
				</div>

				{form_field field=[
					'name' => 'out_of_stock',
					'type' => 'radio-buttons',
					'required' => false,
					'label' => {l s='Behavior when out of stock' d='Modules.Agilemultisellerpro.Product'},
					'value' => {$product->out_of_stock|intval},
					'availableValues' => [
						0 => {l s='Deny orders' d='Modules.Agilemultisellerpro.Product'},
						1 => {l s='Allow orders' d='Modules.Agilemultisellerpro.Product'},
						2 => {l s='Use default behavior (Deny orders)' d='Modules.Agilemultisellerpro.Product'}
					],
					'maxLength' => 0,
					'errors' => [],
					'autocomplete' => ''
				]}

			{else}
				<div class="alert alert-warning">
					<p>{l s='It is not possible to manage quantities when:' d='Modules.Agilemultisellerpro.Product'}</p>
					<ul>
						<li>{l s='You are currently managing all of your shops.' d='Modules.Agilemultisellerpro.Product'}</li>
						<li>
							{l s='You are currently managing a group of shops where quantities are not shared between every shop in this group.' d='Modules.Agilemultisellerpro.Product'}
						</li>
						<li>
							{l s='You are currently managing a shop that is in a group where quantities are shared between every shop in this group.' d='Modules.Agilemultisellerpro.Product'}
						</li>
					</ul>
				</div>
			{/if}
		{/if}
	</div>

	<div class="panel">
		<h3>{l s='Availability settings' d='Modules.Agilemultisellerpro.Product'}</h3>

		{if !$product->hasAttributes()}
			{form_field field=[
				'name' => 'minimal_quantity',
				'type' => 'number',
				'required' => true,
				'label' => {l s='Minimum quantity' d='Modules.Agilemultisellerpro.Product'},
				'value' => {$product->minimal_quantity|intval},
				'availableValues' => [
					'comment' => {l s='The minimum quantity to buy this product (set to 1 to disable this feature)' d='Modules.Agilemultisellerpro.Product'}
				],
				'maxLength' => 0,
				'errors' => [],
				'autocomplete' => ''
			]}
		{/if}

		{if $field.availableValues.ps_stock_management}

			{include file="module:agilemultisellerpro/views/templates/front/_partials/form-fields.tpl"
				languages=$languages
				field=[
					'name' => 'available_now',
					'type' => 'text_lang',
					'required' => false,
					'label' => {l s='Label when in stock' d='Modules.Agilemultisellerpro.Product'},
					'value' => $product->available_now,
					'maxLength' => 0,
					'errors' => [],
					'autocomplete' => '',
					'isLang' => true
				]
			}

			{include file="module:agilemultisellerpro/views/templates/front/_partials/form-fields.tpl"
				languages=$languages
				field=[
					'name' => 'available_later',
					'type' => 'text_lang',
					'required' => false,
					'label' => {l s='Label when out of stock (and backorders allowed)' d='Modules.Agilemultisellerpro.Product'},
					'value' => $product->available_later,
					'maxLength' => 0,
					'errors' => [],
					'autocomplete' => '',
					'isLang' => true
				]
			}

			{form_field field=[
				'name' => 'available_date',
				'type' => 'date',
				'required' => false,
				'label' => {l s='Availability date' d='Modules.Agilemultisellerpro.Product'},
				'value' => $product->available_date,
				'availableValues' => [
					'comment' => {l s='The date until which the product is available' d='Modules.Agilemultisellerpro.Product'}
				],
				'maxLength' => 0,
				'errors' => [],
				'autocomplete' => ''
			]}

		{/if}

{/if}
