{*
* 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}
		<h3>{l s='Product Import' d='Modules.Agilemultisellerpro.Business'}</h3>

		{if $import_confirmation}
			<div class="alert alert-success clearfix">
				{l s='Your .CSV file has been successfully imported into your shop. Don\'t forget to re-build the products\' search index.' d='Modules.Agilemultisellerpro.Import'}
			</div>
		{/if}


		<div class="row">
			<div class="col-md-8">
				{* Import fieldset *}
				<div class="panel">
					<div class="alert alert-info">
						{if !$import_done}
							<ul class="list-unstyled">
								<li>
									{l s='You can read information on import at:' d='Modules.Agilemultisellerpro.Import'}
									<a href="https://docs.prestashop-project.org/1.7-documentation/user-guide/configuring-shop/advanced-parameters/import"
										target="_blank">{l s='link' d='Modules.Agilemultisellerpro.Import'}</a>
								</li>

								<li>
									{l s='Read more about the CSV format at:' d='Modules.Agilemultisellerpro.Import'}
									<a href="http://en.wikipedia.org/wiki/Comma-separated_values"
										target="_blank">{l s='link' d='Modules.Agilemultisellerpro.Import'}</a>
								</li>

								<li>
									{l s='You can download sample product CSV data here:' d='Modules.Agilemultisellerpro.Import'}
									<a href="{$link->getBaseLink()|escape:'htmlall':'UTF-8'}docs/csv_import/products_import.csv"
										target="_blank" download="products_import.csv">{l s='link' d='Modules.Agilemultisellerpro.Import'}</a>
								</li>

								<li>
									{l s='Note that you can have several products with the same reference.' d='Modules.Agilemultisellerpro.Import'}
								</li>
							</ul>
						{else}
							<span>{l s='Product import has been finished successfully.' d='Modules.Agilemultisellerpro.Import'}</span>
						{/if}
					</div>
					<hr />

					<form id="preview_import" action="{$link->getModuleLink('agilemultisellerpro','productimport',[],true)|escape:'htmlall':'UTF-8'}"
						method="post" enctype="multipart/form-data" class="form-horizontal">
						<div class="form-group row" style="display:none;">
							<label for="entity"
								class="control-label col-md-4">{l s='What kind of entity would you like to import?' d='Modules.Agilemultisellerpro.Import'}
							</label>
							<div class="col-md-8">
								<select name="entity" id="entity" class="fixed-width-xxl form-control">
									{foreach $entities AS $entity => $i }
										<option value="{$i|escape:'htmlall':'UTF-8'}" {if $entity_selected == $i} selected="selected" {/if}>
											{$entity|escape:'htmlall':'UTF-8'}
										</option>
									{/foreach}
								</select>
							</div>
						</div>
						<div class="form-group row" id="csv_file_uploader">
							<label for="file" class="control-label col-md-4">{l s='Select CSV Source From' d='Modules.Agilemultisellerpro.Import'}</label>
							<div id="csv_file_options" class="col-md-8">
								<input id="file" type="file" name="file"
									class="js-import-file"
									data-url="{$link->getModuleLink('agilemultisellerpro','productimport',['ajax'=>1,'action'=>'uploadCsv'],true)|escape:'htmlall':'UTF-8'}"
									style="display:none;" />
								<button class="ladda-button btn btn-primary" data-style="expand-right" data-size="s" type="button"
									id="file-add-button">
									<i class="icon-folder-open"></i>
									{l s='Upload' d='Modules.Agilemultisellerpro.Import'}
								</button>
								{l s='or' d='Modules.Agilemultisellerpro.Import'}
								<button id="btn_csv_url" class="btn btn-primary" type="button">
									<span class="icon-folder-open"></span>
									{l s="URL" d='Modules.Agilemultisellerpro.Import'}
								</button>
								{l s='or' d='Modules.Agilemultisellerpro.Import'}
								<button class="btn btn-primary csv-history-btn" type="button">
									{l s="History" d='Modules.Agilemultisellerpro.Import'}(<span class="csv-history-nb badge">{$files_to_import|count}</span>)
								</button>
								<p class="help-block" style="word-break: break-word;">
									{l s='Only UTF-8 and ISO 8859-1 encodings are allowed' d='Modules.Agilemultisellerpro.Import'}.<br />
									{l s='You can also upload your file via FTP to the following directory: %s .'  d='Modules.Agilemultisellerpro.Import' sprintf=['%s' =>$path_import]}
								</p>
							</div>
							<div class="alert alert-danger" id="file-errors" style="display:none"></div>
						</div>
						<div class="form-group row" id="csv_files_url_header" style="display:none;">
							<label for="btn_remove_csv_url" class="control-label col-md-4"></label>
							<div class="col-md-8">
								<span>{l s='Download a CSV file from remote server via URL' d='Modules.Agilemultisellerpro.Import'}</span>
								<button type="button" id="btn_remove_csv_url" class="btn btn-link pull-right">
									<i class="icon-remove"></i>
								</button>
							</div>
						</div>
						<div class="form-group row" id="csv_files_url" style="display:none;">
							<label for="csv_url" class="control-label col-md-4">
								<span title="" data-toggle="tooltip" class="label-tooltip"
									data-original-title="{l s='The locale must be installed' d='Modules.Agilemultisellerpro.Import'}">
									{l s='URL of CSV' d='Modules.Agilemultisellerpro.Import'}
								</span>
							</label>
							<div class="col-md-8">
								<input type="text" name="csv_url" id="csv_url" class="fixed-width-xs form-control" value="">
								<br>
								<button name="btn_get_csv_url" id="btn_get_csv_url"
									class="btn btn-primary pull-right">{l s='Continue' d='Modules.Agilemultisellerpro.Import'}
							</div>
						</div>
						<div class="form-group row" id="csv_files_history" style="display:none;">
							<div class="panel">
								<div class="panel-heading">
									{l s='History of uploaded. CSV' d='Modules.Agilemultisellerpro.Import'}
									<span class="csv-history-nb badge">{$files_to_import|count}</span>
									<button type="button" class="btn btn-link pull-right csv-history-btn">
										<i class="icon-remove"></i>
									</button>
								</div>
								<table id="csv_uploaded_history" class="table">
									{foreach $files_to_import AS $filename}
										<tr>
											<td>
												{$filename|escape:'htmlall':'UTF-8'}
											</td>
											<td>
												<div class="btn-group pull-right">
													<button type="button" data-filename="{$filename|escape:'html':'UTF-8'}"
														class="csv-use-btn btn btn-primary">
														<i class="icon-ok"></i>
														{l s='Use' d='Modules.Agilemultisellerpro.Import'}
													</button>
													<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
														<i class="icon-chevron-down"></i>
													</button>
													<ul class="dropdown-menu" role="menu">
														<li>
															<a href="{$link->getModuleLink('agilemultisellerpro','productimport',[],true)|escape:'htmlall':'UTF-8'}?csvfilename={$filename|escape:'html':'UTF-8'}"
																target="_blank">
																<i class="icon-download"></i>
																{l s='Download' d='Modules.Agilemultisellerpro.Import'}
															</a>
														</li>
														<li class="divider"></li>
														<li>
															<a
																href="{$link->getModuleLink('agilemultisellerpro','productimport',[],true)|escape:'htmlall':'UTF-8'}?csvfilename={$filename|escape:'html':'UTF-8'}&amp;delete=1">
																<i class="icon-trash"></i>
																{l s='Delete' d='Modules.Agilemultisellerpro.Import'}
															</a>
														</li>
													</ul>
												</div>
											</td>
										</tr>
									{/foreach}
								</table>
							</div>
						</div>
						<div class="form-group row" id="csv_file_selected" style="display: none;">
							<div class="col-md-12">
								<div class="alert alert-success clearfix">
									<input type="hidden" value="{$csv_selected|escape:'htmlall':'UTF-8'}" name="csv" id="csv_selected_value" />
									<div class="col-md-8">
										<span id="csv_selected_filename">
											{if $csv_selected}
												{$csv_selected|escape:'html':'UTF-8'}
											{else}
												{l s='Please specify the file to import' d='Modules.Agilemultisellerpro.Import'}
											{/if}
										</span>
									</div>
									<div class="col-md-4">
										<div class="btn-group pull-right">
											<button id="file-remove-button" type="button" class="btn btn-primary">
												{* <i class="icon-refresh"></i> *}
												{l s='Specify' d='Modules.Agilemultisellerpro.Import'}
											</button>
										</div>
									</div>
								</div>
							</div>
						</div>

						<hr />

						<div class="form-group row">
							<label class="form-control-label col-md-4" for="iso_lang">{l s='Language of the file'  d='Modules.Agilemultisellerpro.Import'}</label>

							<div class="col-md-8">
								<select class="form-control" name="iso_lang" id="iso_lang">
									{foreach $languages as $lang}
										<option value="{$lang.iso_code|escape:'htmlall':'UTF-8'}" {if $lang.id_lang == $id_language} selected="selected" {/if}>
											{$lang.name|escape:'htmlall':'UTF-8'}
										</option>
									{/foreach}
								</select>
							</div>
						</div>

						{* <div class="form-group row">
							<label class="form-control-label col-md-4" for="convert">{l s='ISO 8859-1 encoded file?' d='Modules.Agilemultisellerpro.Import'}</label>

							<div class="col-md-8 form-control-label">
								<span class="custom-checkbox">
									<label>
										<input name="convert" id="convert" type="checkbox" value="1">
										<span><i class="material-icons rtl-no-flip checkbox-checked">&#xE5CA;</i></span>
									</label>
								</span>
							</div>
						</div> *}
						<input name="convert" id="convert" type="hidden" value="0">

						<div class="form-group row">
							<label for="separator" class="form-control-label col-md-4">{l s='Field separator' d='Modules.Agilemultisellerpro.Import'}</label>

							<div class="col-md-8">
								<input id="separator" name="separator" class="fixed-width-xs form-control" type="text"
									value="{if isset($separator_selected)}{$separator_selected|escape:'html':'UTF-8'}{else};{/if}" />
								<div class="help-block">{l s='e.g. ' d='Modules.Agilemultisellerpro.Import'} 1; Blouse; 129.90; 5</div>
							</div>
						</div>

						<div class="form-group row">
							<label for="multiple_value_separator"
								class="form-control-label col-md-4">{l s='Multiple value separator' d='Modules.Agilemultisellerpro.Import'}</label>

							<div class="col-md-8">
								<input id="multiple_value_separator" name="multiple_value_separator" class="fixed-width-xs form-control"
									type="text"
									value="{if isset($multiple_value_separator_selected)}{$multiple_value_separator_selected|escape:'html':'UTF-8'}{else},{/if}" />
								<div class="help-block">{l s='e.g. ' d='Modules.Agilemultisellerpro.Import'} Blouse; red.jpg, blue.jpg,
									green.jpg; 129.90</div>
							</div>
						</div>

						<hr>

						<div class="form-group row">
							<label for="truncate"
								class="form-control-label col-md-4">{l s='Delete all before import' d='Modules.Agilemultisellerpro.Import'}
							</label>
							<div class="col-md-8 form-control-label">
								<span class="custom-checkbox">
									<label>
										<input name="truncate" id="truncate" type="checkbox" value="1">
										<span><i class="material-icons rtl-no-flip checkbox-checked">&#xE5CA;</i></span>
									</label>
								</span>
							</div>
						</div>

						<div class="form-group row" style="display: none">
							<label for="match_ref"
								class="form-control-label col-md-4">{l s='Use product reference as key' d='Modules.Agilemultisellerpro.Import'}
							</label>
							<div class="col-md-8 form-control-label">
								<span class="custom-checkbox">
									<label>
										<input name="match_ref" id="match_ref" type="checkbox" value="1">
										<span><i class="material-icons rtl-no-flip checkbox-checked">&#xE5CA;</i></span>
									</label>
								</span>
							</div>
						</div>

						<div class="form-group row">
							<label for="regenerate"
								class="form-control-label col-md-4">{l s='Do not regenerate thumbnails' d='Modules.Agilemultisellerpro.Import'}
							</label>
							<div class="col-md-8 form-control-label">
								<span class="custom-checkbox">
									<label>
										<input name="regenerate" id="regenerate" type="checkbox" value="1">
										<span><i class="material-icons rtl-no-flip checkbox-checked">&#xE5CA;</i></span>
									</label>
								</span>
							</div>
						</div>

						{* <div class="form-group row">
							<label for="forceIDs"
								class="form-control-label col-md-4">{l s='Force all ID numbers' d='Modules.Agilemultisellerpro.Import'}
							</label>
							<div class="col-md-8 form-control-label">
								<span class="custom-checkbox"
									title="{l s='If you enable this option, your imported items\' ID number will be used as-is. If you do not enable this option, the imported ID number will be ignored, and PrestaShop will instead create auto-incremented ID numbers for all the imported items.' d='Modules.Agilemultisellerpro.Import'}">
									<label>
										<input name="forceIDs" id="forceIDs" type="checkbox" value="1">
										<span><i class="material-icons rtl-no-flip checkbox-checked">&#xE5CA;</i></span>
									</label>
								</span>
							</div>
						</div> *}

						<input name="forceIDs" id="forceIDs" type="hidden" value="0">

						<!--
					{*if empty($files_to_import)*}
					<div class="alert alert-info">{l s='You must upload a file in order to proceed to the next step' d='Modules.Agilemultisellerpro.Import'}</div>
					{*if !count($files_to_import)*}
					<p>{l s='There is no CSV file available. Please upload one using the \'Upload\' button above.' d='Modules.Agilemultisellerpro.Import'}</p>
	-->
						<div class="panel-footer">
							<button type="submit" name="submitImportFile" id="submitImportFile" class="btn btn-primary pull-right">
								<i class="process-icon-next"></i> <span>{l s='Next step' d='Modules.Agilemultisellerpro.Import'}</span>
							</button>
						</div>
					</form>
				</div>
			</div>
			<div class="col-md-4" style="height: 80vh; overflow-y: auto;">
				{* Available and required fields *}
				<div class="panel">
					<h3>
						<i class="icon-list-alt"></i>
						{l s='Available fields' d='Modules.Agilemultisellerpro.Import'}
					</h3>
					<div id="availableFields" class="alert alert-info">
						{$available_fields nofilter}
					</div>
					<p>{l s='* Required field' d='Modules.Agilemultisellerpro.Import'}</p>
				</div>
			</div>
		</div>
	{/if}
{/block}
