{include file="orderforms/$carttpl/common.tpl"}
<div class="main-grid{if $mainGrid} {$mainGrid}{/if}">
    {* {if $RSThemes['pages'][$templatefile]['config']['hideSidebar'] != '1'}
        <div class="main-sidebar">
            {if $RSThemes['addonSettings']['sticky_sidebars'] == "true"}<div class="sidebar-sticky" {if $RSThemes.addonSettings.show_affixed_navigation == 'enabled'}data-sidebar-sticky{/if}>{/if}
                {include file="orderforms/$carttpl/sidebar-categories.tpl"}
            {if $RSThemes['addonSettings']['sticky_sidebars'] == "true"}</div>{/if}
        </div>
    {/if} *}
    <div class="main-content{if $mainContentClasses} {$mainContentClasses}{/if}">
        {* {if $RSThemes['pages'][$templatefile]['config']['hideSidebar'] != '1'}
            {include file="orderforms/$carttpl/sidebar-categories-collapsed.tpl"}
        {/if} *}
        {if $renewalsData}
            {assign var=iconsPages value=['clientareadomains', 'supportticketslist', 'clientareainvoices', 'clientareaproducts', 'clientareaquotes']}
            <div class="alert alert-lagom alert-danger w-hidden" data-renewal-alert-no-domain>
                <div class="alert-body">
                    {$LANG.domainrenewalsnoneavailable}
                </div>
            </div>
            <div class="alert alert-lagom alert-success w-hidden" data-renewal-alert-added>
                <div class="alert-body">
                    {$rslang->trans('order.renew_all_success')}
                </div>
            </div>
            <div class="alert alert-primary alert-lagom alert-domain-renewals hidden" data-domain-renewals-add-all-container>
                <div class="alert-content">
                    <div class="icon">
                        {if is_array($graphics['domain']) && $graphics['domain'][6]->enabled && $graphics['domain'][6]->getJson()->condensed->type}
                            <div class="graphic-item">
                                {assign var=graphic value=$graphics['domain'][6]->getJson()->condensed->graphic}
                                {assign var=graphicType value=$graphics['domain'][6]->getJson()->condensed->type}
                                {if $graphicType == "icon"}
                                    {include file="$template/assets/svg-icon/{$graphic}"}
                                {else if $graphicType == "font-icon"}
                                    <span class="graphic-item-bg">
                                        <i class="{$graphic}"></i>
                                    </span>
                                {else if $graphicType == "media"}
                                    <img src="{$WEB_ROOT}/templates/{$template}/assets/img/page-manager/{$graphic}" alt="{$service.product}">
                                {/if}
                            </div>
                        {else}
                            {include file="$template/includes/common/svg-icon.tpl" icon="64-free-domain-name-3"}
                        {/if}
                    </div>
                    <div class="description">
                        <p class="title p-lg">{$rslang->trans('order.renew_domains')}</p>
                        <span class="desc p-d m-b-0">{$rslang->trans('order.renew_all_desc')|sprintf2:"<span data-domain-renewals-add-all-counter></span>"}</span>
                    </div>
                </div>
                <div class="alert-action">
                    <button tabindex="0" type="button"
                        data-check-renew-url="{$WEB_ROOT}/modules/addons/RSThemes/src/Api/clientApi.php?controller=ClientData&method=getCountClientRenewDomains"
                        data-ajax-url="{$WEB_ROOT}/modules/addons/RSThemes/src/Api/clientApi.php?controller=ClientData&method=doClientRenewDomains"
                        data-renewals-in-cart="{$renewalsInCart}"
                        data-domain-renewals-add-all
                        class="btn btn-primary-faded"
                        >
                        <span class="btn-text"><i class="ls ls-refresh"></i>{$rslang->trans('order.renew_all')}</span>
                        <div class="loader loader-button hidden" >
                            {include file="$template/includes/common/loader.tpl" classes="spinner-sm"}
                        </div>
                    </button>
                </div>
            </div> 
            {$domidsArray = false}
            {if $domids}
                {$domidsArray = $domids|json_encode}
            {/if}
            {include file="$template/includes/tablelist.tpl" tableName="RenewalList" ajaxUrl="/modules/addons/RSThemes/src/Api/clientApi.php?controller=ClientData&method=getClientDomainRenewals" tableIncludes="domain-renewals" startOrderCol="2" filterColumn="2" domids=$domidsArray}
            <script type="text/javascript">
                jQuery(document).ready( function ()
                {
                    {if isset($RSThemes.addonSettings.enable_table_ajax_load) && $RSThemes.addonSettings.enable_table_ajax_load == "enabled"}
                    {else}
                        jQuery('.table-container').removeClass('loading');
                        jQuery('#tableLoading').addClass('hidden');
                    {/if}
                });
            </script>
            <div class="table-container {if isset($RSThemes.addonSettings.enable_table_ajax_load) && $RSThemes.addonSettings.enable_table_ajax_load == "enabled"}table-container-ajax{/if} loading">
                {* <div class="table-top">
                    <div class="d-flex">
                        <label>{$LANG.clientareahostingaddonsview}</label>
                        <div class="dropdown view-filter-btns {if $RSThemes.addonSettings.show_status_icon == 'displayed' && in_array($templatefile, $iconsPages)}iconsEnabled{/if}" >
                            <button tabindex="0" type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
                                {if $RSThemes.addonSettings.show_status_icon == 'displayed' && in_array($templatefile, $iconsPages)}
                                    {if file_exists("templates/$template/assets/img/status-icons/status-all.tpl")}
                                        <span class="status-icon status-status-all" style="font-size: 0;">
                                            {include file="$template/assets/img/status-icons/status-all.tpl"}
                                        </span>
                                    {/if}
                                {else}
                                    <span class="status hidden"></span>
                                {/if}
                                <span class="filter-name">{$rslang->trans('generals.all_entries')}</span>
                                <i class="ls ls-caret"></i>
                            </button>
                            <ul class="dropdown-menu" role="menu">
                                <li>
                                    <a tabindex="0" href="#">
                                        <span data-value="all">
                                            {if $RSThemes.addonSettings.show_status_icon == 'displayed'}
                                                {if file_exists("templates/$template/assets/img/status-icons/status-all.tpl")}
                                                    <span class="status-icon status-status-all">
                                                        {include file="$template/assets/img/status-icons/status-all.tpl"}
                                                    </span>
                                                {/if}
                                                <span class="filter-name">{$rslang->trans('generals.all_entries')}</span>
                                            {else}
                                                {$rslang->trans('generals.all_entries')}
                                            {/if}
                                        </span>
                                    </a>
                                </li>
                                {foreach key=num item=status from=$RSDomainsStatuses}
                                    {if $RSThemes.addonSettings.show_status_icon == 'displayed' && in_array($templatefile, $iconsPages)}
                                        <li>
                                            <a tabindex="0" href="#">
                                                <span class="status status-{$status.statusClass} {if $RSThemes.addonSettings.show_status_icon == 'displayed'}dot-hidden{/if}" data-value="{$status.status}" data-status-class="{$status.statusClass}">
                                                    {if $RSThemes.addonSettings.show_status_icon == 'displayed'}
                                                        {if file_exists("templates/$template/assets/img/status-icons/{$status.statusClass}.tpl")}
                                                            <span class="status-icon status-{$status.statusClass}">
                                                                {include file="$template/assets/img/status-icons/{$status.statusClass}.tpl"}
                                                            </span>
                                                        {else}
                                                            <span class="status-icon status-{$status.statusClass}">
                                                                {include file="$template/assets/img/status-icons/default.tpl"}
                                                            </span>
                                                        {/if}
                                                    {/if}
                                                    <span class="filter-name">
                                                        {if $status.status == "freeWithService"}
                                                            {lang key='domainRenewal.freeWithService'}
                                                        {elseif $status.status == "unavailable"}
                                                            {lang key='domainunavailable'}
                                                        {elseif $status.status == "domainrenewalspastgraceperiod"}
                                                            {lang key='domainrenewalspastgraceperiod'}
                                                        {elseif $status.status == "beforeRenewLimitDays"}
                                                            {$rslang->trans('order.beforeRenewLimit')}
                                                        {elseif $status.status = "availableforrenewal"}
                                                            {lang key='orderavailable'}
                                                        {/if}
                                                    </span>
                                                </span>
                                            </a>
                                        </li>
                                    {else}
                                        <li><a tabindex="0" href="#">
                                            <span class="status status-{$status.statusClass}" data-value="{$status.status}" data-status-class="{$status.statusClass}">
                                                {if $status.status == "freeWithService"}
                                                    {lang key='domainRenewal.freeWithService'}
                                                {elseif $status.status == "unavailable"}
                                                    {lang key='domainunavailable'}
                                                {elseif $status.status == "domainrenewalspastgraceperiod"}
                                                    {lang key='domainrenewalspastgraceperiod'}
                                                {elseif $status.status == "beforeRenewLimitDays"}
                                                    {$rslang->trans('order.beforeRenewLimit')}
                                                {elseif $status.status = "availableforrenewal"}
                                                    {lang key='orderavailable'}
                                                {/if}
                                            </span>
                                        </a></li>
                                    {/if}
                                {/foreach}
                            </ul>
                        </div>
                        <button tabindex="0" id="clearFilters" type="button" class="btn btn-link btn-xs hidden">{$rslang->trans('generals.clear_filters')}<i class="ls ls-close"></i></button>
                    </div>
                </div> *}
                <table id="tableRenewalList" class="table table-list">
                    <thead>
                        <tr>
                            <th data-priority="1"><button tabindex="0" type="button" class="btn-table-collapse"></button>Domain<span class="sorting-arrows"></span></th>
                            <th data-priority="5">Expiry date<span class="sorting-arrows"></span></th>
                            <th data-priority="2" aria-hidden="true"></th>
                        </tr>
                    </thead>
                    <tbody>
                    {if ! isset($RSThemes.addonSettings.enable_table_ajax_load) || $RSThemes.addonSettings.enable_table_ajax_load == "disabled"}
                        {foreach key=num item=renewal from=$renewalsData}
                            <tr>
                                <td class="cell-domain">
                                    <button tabindex="0" type="button" class="btn-table-collapse"></button>
                                    {$renewal.domain}
                                </td>
                                <td class="cell-date">
                                    {$renewal.expiryDate->format('d/m/Y')}
                                    {if ! $renewal.beforeRenewLimit && $renewal.daysUntilExpiry > 0}
                                        <i data-toggle="tooltip" tabindex="0" class="ls ls-info-circle tooltip-icon"
                                           title="{lang key='domainRenewal.expiringIn' days=$renewal.daysUntilExpiry}"
                                           aria-label="{lang key='domainRenewal.expiringIn' days=$renewal.daysUntilExpiry}"></i>
                                    {elseif $renewal.daysUntilExpiry === 0}
                                        <i data-toggle="tooltip" tabindex="0" class="ls ls-info-circle tooltip-icon"
                                           title="{lang key='expiresToday'}"
                                           aria-label="{lang key='expiresToday'}"></i>
                                    {elseif $renewal.beforeRenewLimit}
                                        <i data-toggle="tooltip" tabindex="0" class="ls ls-info-circle tooltip-icon"
                                           title="{lang key='domainRenewal.maximumAdvanceRenewal' days=$renewal.beforeRenewLimitDays}"
                                           aria-label="{lang key='domainRenewal.maximumAdvanceRenewal' days=$renewal.beforeRenewLimitDays}"></i>
                                    {elseif $renewal.daysUntilExpiry < 0}
                                        {assign var="expiredDays" value=$renewal.daysUntilExpiry*-1}
                                        <i data-toggle="tooltip" tabindex="0" class="ls ls-info-circle tooltip-icon"
                                           title="{lang key='domainRenewal.expiredDaysAgo' days=$expiredDays}"
                                           aria-label="{lang key='domainRenewal.expiredDaysAgo' days=$expiredDays}"></i>
                                    {/if}
                                </td>
                                <td class="cell-actions">
                                    <div class="cell-action-container">
                                        {if !$renewal.eligibleForRenewal}
                                            {if $renewal.freeDomainRenewal}
                                                <span class="label label-info">{lang key='domainRenewal.freeWithService'}</span>
                                            {else}
                                                <span class="label label-info">{lang key='domainRenewal.unavailable'}</span>
                                            {/if}
                                        {elseif $renewal.pastGracePeriod && $renewal.pastRedemptionGracePeriod}
                                            <span class="label label-info">{lang key='domainrenewalspastgraceperiod'}</span>
                                        {elseif $renewal.beforeRenewLimit}
                                            <span class="label label-info">{lang key='domainRenewal.maximumAdvanceRenewal' days=$renewal.beforeRenewLimitDays}</span>
                                        {else}
                                            {if $renewal.renewalOptions|@count > 0}
                                                <label for="renewalPricing{$renewal.id}" class="sr-only">{$renewal.domain}</label>
                                                <select class="form-control form-control-sm select-renewal-pricing" id="renewalPricing{$renewal.id}">
                                                    {foreach from=$renewal.renewalOptions item=option}
                                                        <option value="{$option.period}">
                                                            {$option.period} {lang key='orderyears'} @ {$option.rawRenewalPrice}
                                                        </option>
                                                    {/foreach}
                                                </select>
                                            {/if}
                                            <button tabindex="0"
                                                    class="btn btn-sm {if $renewal.inCart}btn-primary{else}btn-primary-faded{/if} btn-add-renewal-to-cart"
                                                    data-domain-id="{$renewal.id}"
                                                    id="renewDomain{$renewal.id}">
                                                <div class="loader loader-button">
                                                    <div class="spinner spinner-sm">
                                                        <div class="rect1"></div>
                                                        <div class="rect2"></div>
                                                        <div class="rect3"></div>
                                                        <div class="rect4"></div>
                                                        <div class="rect5"></div>
                                                    </div>
                                                </div>
                                                <span class="to-add {if $renewal.inCart}w-hidden{/if}">{lang key='addtocart'}</span>
                                                <span class="added {if !$renewal.inCart}w-hidden{/if}">{lang key='domaincheckeradded'}</span>
                                            </button>
                                        </div>
                                    {/if}
                                </td>
                            </tr>
                        {/foreach}
                    {/if}
                    </tbody>
                </table>
                <div class="loader loader-table" id="tableLoading">
                    {include file="$template/includes/common/loader.tpl"}
                </div>
            </div>
        {else}
            <div class="message message-no-data">
                <div class="message-image">
                    {include file="$template/includes/common/svg-icon.tpl" icon="domain"}
                </div>
                <h6 class="message-title">{lang key='domainRenewal.noDomains'}</h6>
            </div>
        {/if}
    </div>
    {if $renewalsData}
        <div class="main-sidebar main-sidebar-summary {if $RSThemes['pages'][$templatefile]['config']['hideSidebar'] == '1'} main-sidebar-lg{/if}">
            <div class="sidebar-sticky sidebar-sticky-summary">
                <div class="panel panel-summary panel-summary-{$summaryStyle} m-b-0x" id="orderSummary">
                    <div class="loader" id="orderSummaryLoader">
                        {if $summaryStyle == 'default'}
                            {include file="$template/includes/common/loader.tpl" classes="spinner-sm"}
                        {else}
                            {include file="$template/includes/common/loader.tpl" classes="spinner-sm spinner-light"}
                        {/if}
                    </div>
                    <div class="panel-heading">
                        <h2 class="panel-title">{$LANG.ordersummary}</h2>
                    </div>
                    <div id="producttotal" data-summary-style="{$summaryStyle}"></div>
                </div>
                {if $hasDomainsInGracePeriod}
                    <small class="text-light m-t-20" style="display: block;">* {lang key='domainRenewal.graceRenewalPeriodDescription'}</small>
                {/if}
            </div>
        </div>
        <div class="order-summary order-summary-mob" id="orderSummaryMob" data-fixed-actions href="#orderSummary">
            <a tabindex="0" href="{$WEB_ROOT}/cart.php?a=view" class="btn btn-lg btn-primary-faded btn-checkout" id="checkout">
                <span><i class="ls ls-share" aria-hidden="true"></i> {$LANG.orderForm.checkout}</span>
                <div class="loader loader-button hidden">{include file="$template/includes/common/loader.tpl" classes="spinner-sm"} </div>
            </a>
        </div>
    {/if}
    <form id="removeRenewalForm" method="post" action="{$WEB_ROOT}/cart.php">
        <input type="hidden" name="a" value="remove" />
        <input type="hidden" name="r" value="" id="inputRemoveItemType" />
        <input type="hidden" name="i" value="" id="inputRemoveItemRef" />
        <div class="modal fade modal-remove-item" id="modalRemoveItem" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button tabindex="0" type="button" class="close" data-dismiss="modal" aria-label="{lang key='orderForm.close'}">
                            <i class="lm lm-close"></i>
                        </button>
                        <h3 class="modal-title">
                            <span>{lang key='orderForm.removeItem'}</span>
                        </h5>
                    </div>
                    <div class="modal-body">
                        {lang key='cartremoveitemconfirm'}
                    </div>
                    <div class="modal-footer">
                        <button tabindex="0" type="submit" class="btn btn-primary">{lang key='yes'}</button>
                        <button tabindex="0" type="button" class="btn btn-default" data-dismiss="modal">{lang key='no'}</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <script>recalculateRenewalTotals();</script>
</div>