{*
* 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
*}
<div id="agile">
	<div id="product-virtual" class="panel product-tab">
		<h3>{$field.label|escape:'htmlall':'UTF-8'}</h3>

		{if empty($field.availableValues.cache_default_attribute)}
			{$productDownload = $field.availableValues.productDownload}

			{form_field field=[
				'name' => 'is_virtual_good',
				'type' => 'checkbox',
				'required' => false,
				'label' => {l s='This is a virtual product' d='Modules.Agilemultisellerpro.Product'},
				'value' => ($product->is_virtual && $productDownload->active),
				'maxLength' => 0,
				'errors' => [],
				'autocomplete' => ''
			]}

			<div id="tr_downloadable" class="form-group "
				style="display:{if $product->is_virtual && $productDownload->active}{else}none{/if};">

				{form_field field=[
					'name' => 'is_virtual_file',
					'type' => 'radio-buttons',
					'required' => false,
					'label' => {l s='Downloadable?' d='Modules.Agilemultisellerpro.Product'},
					'value' => ($productDownload->id && !empty($productDownload->display_filename)),
					'availableValues' => [
						1 => {l s='Yes' d='Modules.Agilemultisellerpro.Product'},
						0 => {l s='No' d='Modules.Agilemultisellerpro.Product'}
					],
					'maxLength' => 0,
					'errors' => [],
					'autocomplete' => ''
				]}
			</div>

			{* [begin] virtual product *}
			<div id="virtual_good" {if !$productDownload->id OR !$product->is_virtual}style="display:none" {/if}>
				{*   {if !$productDownload->id || $productDownload->active}style="display:none"{/if} *}
				<div class="row">
					<p class="alert alert-error" id="file_missing" style="{if empty($field.availableValues.download_product_file_missing)}display:none;{/if}">
						{$field.availableValues.download_product_file_missing|escape:'htmlall':'UTF-8'}
					</p>
				</div>

				<div id="is_virtual_file_product"> {*    style="display:none;" *}
					{if !$field.availableValues.download_dir_writable}
						<p class="alert">
							{l s='Your download repository is not writable.' d='Modules.Agilemultisellerpro.Product'}<br />
							{$smarty.const._PS_DOWNLOAD_DIR_|escape:'htmlall':'UTF-8'}
						</p>
					{/if}
					{* Don't display file form if the product has combinations *}
					{if empty($field.availableValues.cache_default_attribute)}
						{if $productDownload->id}
							<input type="hidden" id="virtual_product_id" name="virtual_product_id"
								value="{$productDownload->id|intval}" />
						{/if}
						{* table *}

						{form_field field=[
							'name' => 'virtual_product_file',
							'type' => 'file',
							'required' => false,
							'label' => {l s='Upload a file' d='Modules.Agilemultisellerpro.Product'},
							'value' => ($productDownload->id && !empty($productDownload->display_filename)),
							'maxLength' => 0,
							'errors' => [],
							'autocomplete' => ''
						]}

						<img id="imgProcessing"
							class="offset-md-3"
							src="{$base_dir_ssl|escape:'htmlall':'UTF-8'}/modules/agilemultisellerpro/views/img/processing.gif"
							style="display:none;">

						<div id="upload-error" class="form-group row" style="display:none"></div>

						<div id="upload-confirmation" class="form-group row"
							style="{if isset($is_agilevirtual_products_installed) && $is_agilevirtual_products_installed==1}display:none;{/if}">
							<label class="col-md-3">
								<input type="hidden" id="virtual_product_filename" name="virtual_product_filename"
									value="{$productDownload->filename|escape:'htmlall':'UTF-8'}" />
							</label>
							<div class="conf col-md-9">
								{if $productDownload->display_filename && !$productDownload->checkFile()}
									<a class="delete_virtual_product" id="delete_downloadable_product"
										onclick="return ajax_delete_virtual_downloadfile();" href="" class="red">
										<img src="{$base_dir_ssl|escape:'htmlall':'UTF-8'}img/admin/delete.gif"
											alt="{l s='Delete this file' d='Modules.Agilemultisellerpro.Product'}" />
									</a>
								{/if}
							</div>
						</div>

						{if $productDownload->checkFile()}
							<div id="tr_link_to_file" class="form-group row">
								<label class="col-md-3 " for="virtual_product_filename">
									{l s='Link to the file:' d='Modules.Agilemultisellerpro.Product'}
								</label>
								<div class="col-md-9 js-input-column">
									<a href="{$link->getModuleLink('agilemultisellerpro', 'sellerproductdetail', ['id_product'=>$product->id,'action'=>'getVirtualFile'], true)|escape:'htmlall':'UTF-8'}"
										title="">{$productDownload->display_filename|escape:'htmlall':'UTF-8'}</a>
									<a onclick="return ajax_delete_virtual_downloadfile()" href="" class="red delete_virtual_product">
										<i class="material-icons btn-outline-danger" aria-hidden="true">delete</i>
									</a>
								</div>
							</div>
						{/if}

						{form_field field=[
							'name' => 'virtual_product_name',
							'type' => 'text',
							'required' => false,
							'label' => {l s='Filename' d='Modules.Agilemultisellerpro.Product'},
							'value' => {$productDownload->display_filename|escape:'htmlall':'UTF-8'},
							'availableValues' => [
								'comment' => {l s='The full filename with its extension (e.g. Book.pdf)' d='Modules.Agilemultisellerpro.Product'}
							],
							'maxLength' => 0,
							'errors' => [],
							'autocomplete' => ''
						]}

						{form_field field=[
							'name' => 'virtual_product_nb_downloable',
							'type' => 'text',
							'required' => false,
							'label' => {l s='Allowed downloads' d='Modules.Agilemultisellerpro.Product'},
							'value' => {$productDownload->nb_downloadable|intval},
							'availableValues' => [
								'comment' => {l s='Number of allowed downloads per customer - (Set to 0 for unlimited downloads)' d='Modules.Agilemultisellerpro.Product'}
							],
							'maxLength' => 0,
							'errors' => [],
							'autocomplete' => ''
						]}

						{form_field field=[
							'name' => 'virtual_product_expiration_date',
							'type' => 'date',
							'required' => false,
							'label' => {l s='Expiration date' d='Modules.Agilemultisellerpro.Product'},
							'value' => {$productDownload->date_expiration|escape:'htmlall':'UTF-8'},
							'availableValues' => [
								'comment' => {l s='If set, the file will not be downloadable anymore after this date. Leave this blank for no expiration date' d='Modules.Agilemultisellerpro.Product'}
							],
							'maxLength' => 0,
							'errors' => [],
							'autocomplete' => ''
						]}

						{form_field field=[
							'name' => 'virtual_product_nb_days',
							'type' => 'number',
							'required' => false,
							'label' => {l s='Number of days' d='Modules.Agilemultisellerpro.Product'},
							'value' => {$productDownload->nb_days_accessible|intval},
							'availableValues' => [
								'comment' => "{l s='How many days this file can be accessed by customers' d='Modules.Agilemultisellerpro.Product'} ({l s='Set to zero for unlimited access' d='Modules.Agilemultisellerpro.Product'})"
							],
							'maxLength' => 4,
							'errors' => [],
							'autocomplete' => ''
						]}
						{* Feature not implemented *}

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

		{else}
			<div id="error_edit_file" class="alert alert-warning">
				{l s='You cannot edit your file here because you used combinations. Please edit it in the Combinations tab' d='Modules.Agilemultisellerpro.Product'}
			</div>
		{/if}
	</div> <!-- End of panel -->
</div> <!-- End of bootstrap -->
