{*
* 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='customer/page.tpl'}

{block name='page_title'}
	{l s='Membership' d='Modules.Agilemultisellerpro.Membership'}
{/block}

{block name='page_content_container'}
	<div class="page-customer-account">
		<section id="content" class="page-content">

			{if !$content_only}
				{capture name=path}<a
						href="{$link->getPageLink('my-account', true)|escape:'html':'UTF-8'}">{l s='My membership' d='Modules.Agilemultisellerpro.Membership'}</a><span
					class="navigation-pipe">{$navigationPipe|escape:'html':'UTF-8'}</span>{l s='Your membership information' d='Modules.Agilemultisellerpro.Membership'}{/capture}
			{/if}

			<h2 class="agile-seller-information__label">{l s='Your membership information' d='Modules.Agilemultisellerpro.Membership'}</h2>

			{if $confirmation}
				<p class="success">
					{l s='Your membership information has been successfully updated.' d='Modules.Agilemultisellerpro.Membership'}
				</p>
			{else}
				<fieldset>
					<form
						action="{$link->getModuleLink('agilemultisellerpro', 'mymembership', [], true)|escape:'htmlall':'UTF-8'}"
						method="post">
						{if $membership_valid && $membership}
							<p class="text">
								<label
									for="membership_activated">{l s='Membership Type' d='Modules.Agilemultisellerpro.Membership'}:</label>

								{$idMembershipType = $membership->getSellerinfoMembershipType()->getIdMembershipType()|intval}
								{foreach from=$membershiptypes item=membershiptype}
									{if $idMembershipType == $membershiptype.id_membership_type|intval}{$membershiptype.name|escape:'html':'UTF-8'}{/if}
								{/foreach}
								</select>
							</p>

							<p class="text">
								<label for="id_date_add">{l s='Signup Date' d='Modules.Agilemultisellerpro.Membership'}:</label>
								<span id="id_date_add">{dateFormat date=$membership->getDateAdd()->format('Y-m-d H:i:s') full=1}</span>
							</p>

							<p class="text">
								<label
									for="id_activation_date">{l s='Activation Date' d='Modules.Agilemultisellerpro.Membership'}:</label>
								<span id="id_activation_date">{dateFormat date=$membership->getActivationDate()->format('Y-m-d H:i:s') full=1}</span>
							</p>

							<p class="text">
								<label
									for="id_expiry_date">{l s='Expiration Date' d='Modules.Agilemultisellerpro.Membership'}:</label>
								<span id="id_expiry_date">
									{dateFormat date=$expiry_date->format('Y-m-d H:i:s') full=1}
								</span>
							</p>
						{else}
							{l s='You do not have valid membership at this time.' d='Modules.Agilemultisellerpro.Membership'}
						{/if}
					</form>
				</fieldset>
			{/if}
			<br><br>

			<h2>{l s='Your membership history' d='Modules.Agilemultisellerpro.Membership'}</h2>
			{if isset($membership_history) AND count($membership_history)>0}
				<div class="table-responsive clearfix">
					<table class="table responsive">
						<thead>
							<tr>
								<th>{l s='Membership' d='Modules.Agilemultisellerpro.Membership'}</th>
								<th>{l s='Start' d='Modules.Agilemultisellerpro.Membership'}</th>
								<th>{l s='Expires' d='Modules.Agilemultisellerpro.Membership'}</th>
								<th>{l s='Order #' d='Modules.Agilemultisellerpro.Membership'}</th>
								<th>{l s='Order Status' d='Modules.Agilemultisellerpro.Membership'}</th>
								<th>{l s='Products limit used' d='Modules.Agilemultisellerpro.Membership'}</th>
								<th>{l s='Cancelled' d='Modules.Agilemultisellerpro.Membership'}</th>
								<th></th>
							</tr>
						</thead>
						{foreach from=$membership_history item=history}
							<tr>
								<td style="{if $history.is_cancelled==1}text-decoration:line-through{/if}">
									{$history.membership|escape:'html':'UTF-8'}</td>
								<td style="{if $history.is_cancelled==1}text-decoration:line-through{/if}">
									{$history.date_start|escape:'html':'UTF-8'}</td>
								<td style="{if $history.is_cancelled==1}text-decoration:line-through{/if}">
									{$history.expiry_date|escape:'html':'UTF-8'}</td>
								<td style="{if $history.is_cancelled==1}text-decoration:line-through{/if}">
									{$history.order_reference|escape:'html':'UTF-8'}</td>
								<td style="{if $history.is_cancelled==1}text-decoration:line-through{/if}">
									{$history.status|escape:'html':'UTF-8'}</td>
								<td style="{if $history.is_cancelled==1}text-decoration:line-through{/if}">
									{$nbSllerProducts|escape:'html':'UTF-8'} / {if $history.max_products == 0}&infin;{else}{$history.max_products|escape:'html':'UTF-8'}{/if}
								</td>
								<td>{if $history.is_cancelled==1}
										{$history.date_cancelled|escape:'html':'UTF-8'}
									{else if $history.is_cancelled==2}
										{l s='Cancellation request has been submitted on' d='Modules.Agilemultisellerpro.Membership'}
										{$history.date_cancelled|escape:'html':'UTF-8'}
									{else if $history.expiry_date > date('Y-m-d H:i:s')}
										<a class="btn btn-primary"
												href="{$link->getModuleLink('agilemultisellerpro', 'mymembership', ['process' => 'cancel', 'id_membership_history'=>$history.id_membership_history], true)|escape:'html':'UTF-8'}"
												onclick="if (confirm(confirm_cancel_message)){ return true; }else{ event.stopPropagation(); event.preventDefault();};">{l s='Cancel' d='Modules.Agilemultisellerpro.Membership'}</a>
									{/if}
								</td>
								<td><a href=""></a></td>
							</tr>
						{/foreach}
					</table>
				</div>
			{else}
				<p class="alert alert-warning">
					{l s='You do not have membership yet.'  d='Modules.Agilemultisellerpro.Membership'}</p>
			{/if}


			<p>
			<h2>{l s='Available memberships' d='Modules.Agilemultisellerpro.Membership'}</h2>
			</p>

			<div class="table-responsive clearfix">
				{if !empty($mproducts)}
					<table class="table">
						{foreach from=$mproducts item=product}
							<tr>
								<td>
									<div class="col-md-5">
										<p>
											<img class="replace-2x img-responsive"
												src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')|escape:'html':'UTF-8'}"
												alt="{$product.name|escape:'html':'UTF-8'}"
												title="{$product.name|escape:'html':'UTF-8'}" {if isset($homeSize)}
													width="{$homeSize.width|escape:'html':'UTF-8'}"
												height="{$homeSize.height|escape:'html':'UTF-8'}" {/if} itemprop="image" />
										</p>
									</div>
									<div class="col-md-7">
										<h2>{$product.name|escape:'html':'UTF-8'}</h2>
										<p>
											{Tools::displayPrice($product.price)|escape:'html':'UTF-8'}&nbsp;
											<small>
												{$product.units|escape:'html':'UTF-8'}&nbsp;
												{if $product.interval == 'MONTH'}
													{l s='Months' d='Modules.Agilemultisellerpro.Membership'}
												{elseif $product.interval == 'WEEK'}
													{l s='Weeks' d='Modules.Agilemultisellerpro.Membership'}
												{elseif $product.interval == 'DAY'}
													{l s='Days' d='Modules.Agilemultisellerpro.Membership'}
												{elseif $product.interval == 'YEAR'}
													{l s='Years' d='Modules.Agilemultisellerpro.Membership'}
												{/if}
											</small>
										</p>
										<p>{l s='Products limit' d='Modules.Agilemultisellerpro.Membership'}: {if $product.max_products == 0}{l s='Unlimited' d='Modules.Agilemultisellerpro.Membership'}{else}{$product.max_products|escape:'html':'UTF-8'}{/if}</p>
										<p>{l s='Product images limit' d='Modules.Agilemultisellerpro.Membership'}: {if $product.max_product_images == 0}{l s='Unlimited' d='Modules.Agilemultisellerpro.Membership'}{else}{$product.max_product_images|escape:'html':'UTF-8'}{/if}</p>
										<p>
											{if $membership_valid}
												{if $idCurrentMembershipTypeProduct == $product.id_product}
													<a type="button" class="btn btn-primary" name="renew"
														href="{$link->getModuleLink('agilemultisellerpro', 'mymembership', ['process' => 'renew', 'id_product'=>$product.id_product], true)|escape:'html':'UTF-8'}"
														onclick="if (confirm('You membership will be extended when current one expies. Are you sure to want to proceed?')){ return true; }else{ event.stopPropagation(); event.preventDefault();};">{l s='Renew Membership' d='Modules.Agilemultisellerpro.Membership'}</a>
												{else}
													<a type="button" class="btn btn-primary" name="switch"
														href="{$link->getModuleLink('agilemultisellerpro', 'mymembership', ['process' => 'switch', 'id_product'=>$product.id_product], true)|escape:'html':'UTF-8'}"
														onclick="if (confirm('You current membership will be cancelled, and the new membership will become effective when applicable payment is finished?')){ return true; }else{ event.stopPropagation(); event.preventDefault();};">{l s='Switch Membership' d='Modules.Agilemultisellerpro.Membership'}</a>
												{/if}
											{/if}
											<br><br>
											<a type="button" class="btn btn-primary" name="purchase"
												href="{$link->getModuleLink('agilemultisellerpro', 'mymembership', ['process' => 'purchase', 'id_product'=>$product.id_product], true)|escape:'html':'UTF-8'}">{l s='Purchase Membership' d='Modules.Agilemultisellerpro.Membership'}</a>
										</p>

										<p>
											{$product.description|escape:'html':'UTF-8'}
										</p>
									</div>
								</td>
							</tr>
						{/foreach}
					</table>
				{else}
					<div class="text-center">{l s='No available memberships.' d='Modules.Agilemultisellerpro.Membership'}</div>
				{/if}
			</div>

		</section>
	</div>

{/block}

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

	<script type="text/javascript">
		var confirm_cancel_request_message = "{l s='Are you sure to submit a request to cancel this membership?' d='Modules.Agilemultisellerpro.Membership'}";
		var confirm_cancel_message = "{l s='Are you sure to cancel this membership?' d='Modules.Agilemultisellerpro.Membership'}";
		var ok_message = "{l s='Request has been processed success.' d='Modules.Agilemultisellerpro.Membership'}";

		// $(document).ready(function() {
		// 	$('.datepicker').datepicker({
		// 		prevText: '',
		// 		nextText: '',
		// 		dateFormat: 'yy-mm-dd'
		// 	});
		// });
	</script>

{/block}
