{*
 **********************************************************
 * Developed by: Team Theme Metro
 * Website: http://www.thememetro.com
 **********************************************************
*}

{if $services}
{include file="$template/includes/tablelist.tpl" tableName="ServicesList" filterColumn="3" noSortColumns="4"}

<script>
    jQuery(document).ready( function () {
        var table = jQuery('#tableServicesList').show().DataTable();
        {if $orderby == 'product'}
            table.order([0, '{$sort}'], [3, 'asc']);
        {elseif $orderby == 'amount' || $orderby == 'billingcycle'}
            table.order(1, '{$sort}');
        {elseif $orderby == 'nextduedate'}
            table.order(2, '{$sort}');
        {elseif $orderby == 'domainstatus'}
            table.order(3, '{$sort}');
        {/if}
        table.draw();
        jQuery('#tableLoading').hide();
    });
</script>


<div class="table-container clearfix">
	<div class="table-header">
		<label>{$LANG.clientareahostingaddonsview}</label>
		<div class="dropdown view-filter-btns">
			<button type="button" class="btn btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
				<span>All Entries</span> <i class="fas fa-caret-down"></i> 
			</button>
			 <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenuButton">
				<li><a href="#" class="dropdown-item"><span data-value="all">All Entries</span></a></li>
				{foreach key=statustext item=count from=$services|@array_column:'statustext'|@array_count_values}
					<li><a href="#" class="dropdown-item"><span data-value="{$statustext}">{$statustext}</span></a></li>
                {/foreach}
			</ul>
		</div>		
	</div>
	
    <table id="tableServicesList" class="datatable table table-hover w-hidden">
        <thead>
            <tr>
                <th data-class="expand">{lang key='orderproduct'}</th>
                <th data-hide="phone,tablet">{lang key='clientareaaddonpricing'}</th>
                <th data-hide="phone,tablet">{lang key='clientareahostingnextduedate'}</th>
                <th data-hide="phone">{lang key='clientareastatus'}</th>
                <th class="col-small center"></th>
            </tr>
        </thead>
        <tbody>
            {foreach $services as $service}
                <tr onclick="clickableSafeRedirect(event, 'clientarea.php?action=productdetails&amp;id={$service.id}', false)">
                    <td>
						{$service.group} - {$service.product}
						{if $service.domain}<br />
						<small class="text-domain">{$service.domain}</small>
						{/if}						
					
					</td>
                    <td data-order="{$service.amountnum}">{$service.amount} <small class="cycle-text">{if $service.amountnum == '0.00'}{lang key='orderpaymenttermfreeaccount'}{else}{$service.billingcycle}{/if}</small></td>
		{if $service.amountnum == "0.00"}
                  {if $service.status == "Terminated"}
                    <td>
                      Abgelaufen seit {((($smarty.now - ($service.regdate|@strtotime)) / 86400)|round) - 14} Tagen
                    </td>
                  {elseif ($smarty.now - ($service.regdate|@strtotime)) > 1123200} {* wenn Heute - RegisterDatum > 13 Tage *}
                    <td style="color:red;">
                      <span class="w-hidden">{$service.normalisedNextDueDate}</span>
                      Letzter Tag der Trial Periode
                    </td>
                  {elseif ($smarty.now - ($service.regdate|@strtotime)) > 950400} {* wenn Heute - RegisterDatum > 11 Tage *}
                    <td style="color:orange;">
                      <span class="w-hidden">{$service.normalisedNextDueDate}</span>
                      Endet in {(14 - (($smarty.now - ($service.regdate|@strtotime)) / 86400)|round)} Tagen
                    </td>
                  {else}
                    <td>
                      Endet in {(14 - (($smarty.now - ($service.regdate|@strtotime)) / 86400)|round)} Tagen
                    </td>
                  {/if}
		{else}
			<td><span class="w-hidden">{$service.normalisedNextDueDate}</span>{$service.nextduedate}</td>
		{/if}
                    <td><span class="label status status-{$service.status|strtolower}">{$service.statustext}</span></td>
                    <td class="col-small center">
						<a href="#" role="button" class="btn btn-link btn-sm" data-toggle="dropdown">
							<i class="fas fa-ellipsis-h"></i>
						</a>	
						<ul class="dropdown-menu dropdown-menu-right" role="menu">                                        
							<li><a class="dropdown-item" href="clientarea.php?action=productdetails&id={$service.id}">{$LANG.clientareaviewdetails}</a></li>
							{if $service.rawstatus == "active" && ($service.downloads || $service.addons || $service.packagesupgrade)}
								<li class="dropdown-divider"></li>
								{if $service.downloads} <li><a class="dropdown-item" href="clientarea.php?action=productdetails&id={$service.id}#tabDownloads">{$LANG.downloadstitle}</a></li>{/if}
								{if $service.addons} <li><a class="dropdown-item" href="clientarea.php?action=productdetails&id={$service.id}#tabAddons">{$LANG.clientareahostingaddons}</a></li>{/if}
								{if $service.packagesupgrade} <li><a class="dropdown-item" href="upgrade.php?type=package&id={$service.id}">{$LANG.upgradedowngradepackage}</a></li>{/if}
							{/if}                                        
						</ul>
                    </td>
                </tr>
            {/foreach}
        </tbody>
    </table>
    <div class="text-center" id="tableLoading">
        <p><i class="fas fa-spinner fa-spin"></i> {$LANG.loading}</p>
    </div>
</div>

{else}
<div class="alert-lg no-data">
	<div class="icon">
		<i class="fas fa-exclamation-triangle"></i>
	</div>
	<div class="text">
		{$LANG.clientareaproductsnone}
	</div>
	<a class="btn btn-primary" href="{$WEB_ROOT}/{if $themesettings.orderform.orderopc != ""}order{else}cart{/if}.php">
        {$LANG.navservicesorder}
    </a>
</div>
{/if}
