{if $registrarcustombuttonresult=="success"}
    {include file="$template/includes/alert.tpl" type="success" msg="{lang key='moduleactionsuccess'}" textcenter=true}
{elseif $registrarcustombuttonresult}
    {include file="$template/includes/alert.tpl" type="error" msg="{lang key='moduleactionfailed'}" textcenter=true}
{/if}

{if $unpaidInvoice}
    <div class="alert alert-{if $unpaidInvoiceOverdue}danger{else}warning{/if}" id="alert{if $unpaidInvoiceOverdue}Overdue{else}Unpaid{/if}Invoice">
        <div class="float-right">
            <a href="viewinvoice.php?id={$unpaidInvoice}" class="btn btn-xs btn-default">
                {lang key='payInvoice'}
            </a>
        </div>
        {$unpaidInvoiceMessage}
    </div>
{/if}

<div class="tab-content margin-bottom" data-domain-details-tabs>
    <div class="tab-pane fade show active" id="tabOverview">
        <section class="dashboard-domain-overview">
            <div class="dashboard-domain-overview__header">
                <div class="dashboard-page-heading__title">
                    <span class="dashboard-page-heading__icon"><i class="fas fa-globe"></i></span>
                    <div>
                        <h1 class="dashboard-page-title">{lang key='overview'}</h1>
                    </div>
                    <span class="status-pill {if $systemStatus == 'Active'}success{elseif $systemStatus == 'Pending'}warning{else}muted{/if}">{$status}</span>
                </div>
            </div>

            {if $alerts}
                <div class="dashboard-stack">
                    {foreach $alerts as $alert}
                        {include file="$template/includes/alert.tpl" type=$alert.type msg="<strong>{$alert.title}</strong><br>{$alert.description}" textcenter=true}
                    {/foreach}
                </div>
            {/if}

            {if $systemStatus != 'Active'}
                <div class="dashboard-overview-alert dashboard-overview-alert--warning">
                    <i class="far fa-exclamation-circle"></i>
                    <span>{lang key='domainCannotBeManagedUnlessActive'}</span>
                </div>
            {/if}

            {if $lockstatus eq "unlocked"}
                <div class="dashboard-overview-alert dashboard-overview-alert--danger">
                    <i class="far fa-unlock"></i>
                    <span>{lang key='domaincurrentlyunlockedexp'}</span>
                </div>
            {/if}

            <section class="dashboard-panel dashboard-page-table-panel dashboard-page-table-panel--tight">
                <div class="dashboard-domain-hero">
                    <div class="dashboard-domain-hero__identity">
                        <span class="dashboard-domain-hero__icon"><i class="fas fa-globe"></i></span>
                        <div class="dashboard-domain-hero__copy">
                            <h2>{$domain}</h2>
                            <span class="status-pill {if $systemStatus == 'Active'}success{elseif $systemStatus == 'Pending'}warning{else}muted{/if}">{$status}</span>
                        </div>
                    </div>
                    <div class="dashboard-domain-hero__metrics">
                        <article class="dashboard-overview-metric">
                            <span class="dashboard-overview-metric__icon"><i class="far fa-credit-card"></i></span>
                            <div>
                                <span class="dashboard-overview-metric__label">{lang key='firstpaymentamount'}</span>
                                <strong class="dashboard-overview-metric__value">{$firstpaymentamount}</strong>
                            </div>
                        </article>
                        <article class="dashboard-overview-metric">
                            <span class="dashboard-overview-metric__icon dashboard-overview-metric__icon--blue"><i class="fas fa-sync-alt"></i></span>
                            <div>
                                <span class="dashboard-overview-metric__label">{lang key='recurringamount'}</span>
                                <strong class="dashboard-overview-metric__value">{$recurringamount} / {lang key='every'} {$registrationperiod} {lang key='orderyears'}</strong>
                            </div>
                        </article>
                    </div>
                </div>

                <div class="dashboard-overview-grid">
                    <div class="dashboard-overview-grid__column">
                        <div class="dashboard-overview-row">
                            <span class="dashboard-overview-row__icon"><i class="far fa-calendar-alt"></i></span>
                            <span class="dashboard-overview-row__label">{lang key='clientareahostingregdate'}</span>
                            <span class="dashboard-overview-row__value">{$registrationdate}</span>
                        </div>
                        <div class="dashboard-overview-row">
                            <span class="dashboard-overview-row__icon"><i class="far fa-calendar-alt"></i></span>
                            <span class="dashboard-overview-row__label">{lang key='clientareahostingnextduedate'}</span>
                            <span class="dashboard-overview-row__value">{$nextduedate}</span>
                        </div>
                        <div class="dashboard-overview-row">
                            <span class="dashboard-overview-row__icon dashboard-overview-row__icon--amber"><i class="far fa-info-circle"></i></span>
                            <span class="dashboard-overview-row__label">{lang key='clientareastatus'}</span>
                            <span class="dashboard-overview-row__value"><span class="status-pill {if $systemStatus == 'Active'}success{elseif $systemStatus == 'Pending'}warning{else}muted{/if}">{$status}</span></span>
                        </div>
                        <div class="dashboard-overview-row">
                            <span class="dashboard-overview-row__icon dashboard-overview-row__icon--blue"><i class="fas fa-shield-alt"></i></span>
                            <span class="dashboard-overview-row__label">{lang key='sslState.sslStatus'}</span>
                            <span class="dashboard-overview-row__value">
                                {if $sslStatus}
                                    <span id="statusDisplayLabel">
                                        {if !$sslStatus->needsResync()}
                                            {$sslStatus->getStatusDisplayLabel()}
                                        {else}
                                            {lang key='loading'}
                                        {/if}
                                    </span>
                                {else}
                                    -
                                {/if}
                            </span>
                        </div>
                        <div class="dashboard-overview-row">
                            <span class="dashboard-overview-row__icon dashboard-overview-row__icon--violet"><i class="far fa-user"></i></span>
                            <span class="dashboard-overview-row__label">{lang key='sslState.issuerName'}</span>
                            <span class="dashboard-overview-row__value">
                                {if $sslStatus && (!$sslStatus->needsResync() || $sslStatus->issuerName)}
                                    <span id="ssl-issuer">{$sslStatus->issuerName}</span>
                                {else}
                                    {lang key='loading'}
                                {/if}
                            </span>
                        </div>
                    </div>

                    <div class="dashboard-overview-grid__column">
                        <div class="dashboard-overview-row">
                            <span class="dashboard-overview-row__icon dashboard-overview-row__icon--blue"><i class="far fa-credit-card"></i></span>
                            <span class="dashboard-overview-row__label">{lang key='orderpaymentmethod'}</span>
                            <span class="dashboard-overview-row__value">{$paymentmethod}</span>
                        </div>
                        <div class="dashboard-overview-row">
                            <span class="dashboard-overview-row__icon dashboard-overview-row__icon--violet"><i class="fas fa-redo-alt"></i></span>
                            <span class="dashboard-overview-row__label">{lang key='billingcycle'}</span>
                            <span class="dashboard-overview-row__value">{lang key='every'} {$registrationperiod} {lang key='orderyears'}</span>
                        </div>
                        <div class="dashboard-overview-row">
                            <span class="dashboard-overview-row__icon"><i class="fas fa-shield-alt"></i></span>
                            <span class="dashboard-overview-row__label">{lang key='sslState.startDate'}</span>
                            <span class="dashboard-overview-row__value">
                                {if $sslStatus && ($sslStatus->isActive() || $sslStatus->needsResync())}
                                    <span id="ssl-startdate">
                                        {if !$sslStatus->needsResync() || $sslStatus->startDate}
                                            {$sslStatus->startDate->toClientDateFormat()}
                                        {else}
                                            {lang key='loading'}
                                        {/if}
                                    </span>
                                {else}
                                    -
                                {/if}
                            </span>
                        </div>
                        <div class="dashboard-overview-row">
                            <span class="dashboard-overview-row__icon dashboard-overview-row__icon--amber"><i class="far fa-calendar-alt"></i></span>
                            <span class="dashboard-overview-row__label">{lang key='sslState.expiryDate'}</span>
                            <span class="dashboard-overview-row__value">
                                {if $sslStatus && ($sslStatus->isActive() || $sslStatus->needsResync())}
                                    <span id="ssl-expirydate">
                                        {if !$sslStatus->needsResync() || $sslStatus->expiryDate}
                                            {$sslStatus->expiryDate->toClientDateFormat()}
                                        {else}
                                            {lang key='loading'}
                                        {/if}
                                    </span>
                                {else}
                                    -
                                {/if}
                            </span>
                        </div>
                    </div>
                </div>

                <div class="dashboard-overview-actions">
                    <span class="dashboard-overview-actions__label">{lang key='managedomain'} <i class="far fa-cog"></i></span>
                    <div class="dashboard-overview-actions__buttons">
                        {if $renew}
                            <a href="{routePath('domain-renewal', $domain)}" class="dashboard-action-ghost">
                                <i class="fas fa-redo-alt"></i>
                                {lang key='domainrenew'}
                            </a>
                        {/if}
                        {if $systemStatus == 'Active' && $managementoptions.nameservers}
                            <a class="dashboard-action-ghost tabControlLink" data-toggle="tab" href="#tabNameservers">
                                <i class="far fa-globe"></i>
                                {lang key='changeDomainNS'}
                            </a>
                        {/if}
                        {if $systemStatus == 'Active' && $managementoptions.contacts}
                            <a href="clientarea.php?action=domaincontacts&amp;domainid={$domainid}" class="dashboard-action-ghost">
                                <i class="far fa-user-edit"></i>
                                {lang key='updateWhoisContact'}
                            </a>
                        {/if}
                        <div class="btn-group btn-group-sm dashboard-domain-actions-menu" data-domain-actions-menu>
                            <button type="button" class="dashboard-action-ghost dropdown-toggle dashboard-domain-actions-menu__toggle" data-domain-actions-toggle aria-haspopup="true" aria-expanded="false">
                                <i class="far fa-ellipsis-h"></i>
                                {lang key='more'}
                            </button>
                            <div class="dropdown-menu dropdown-menu-right dashboard-domain-actions-menu__dropdown" data-domain-actions-dropdown>
                                {if $systemStatus == 'Active' && $managementoptions.locking}
                                    <a class="dropdown-item tabControlLink" data-toggle="tab" href="#tabReglock">{lang key='changeRegLock'}</a>
                                {/if}
                                <a class="dropdown-item tabControlLink" data-toggle="tab" href="#tabAutorenew">{lang key='domainsautorenew'}</a>
                            </div>
                        </div>
                    </div>
                </div>
            </section>

            {if $registrarclientarea}
                <div class="moduleoutput">
                    {$registrarclientarea|replace:'modulebutton':'btn'}
                </div>
            {/if}

            {foreach $hookOutput as $output}
                <div>
                    {$output}
                </div>
            {/foreach}
        </section>

    </div>
    <div class="tab-pane fade" id="tabAutorenew">

        <div class="card">
            <div class="card-body">

                <h3 class="card-title">{lang key='domainsautorenew'}</h3>

                {if $changeAutoRenewStatusSuccessful}
                    {include file="$template/includes/alert.tpl" type="success" msg="{lang key='changessavedsuccessfully'}" textcenter=true}
                {/if}

                <p>{lang key='domainrenewexp'}</p>

                <h4 class="text-center mb-4">{lang key='domainautorenewstatus'}: <span class="label label-{if $autorenew}success{else}danger{/if}">{if $autorenew}{lang key='domainsautorenewenabled'}{else}{lang key='domainsautorenewdisabled'}{/if}</span></h4>

                <form method="post" action="{$smarty.server.PHP_SELF}?action=domaindetails#tabAutorenew">
                    <input type="hidden" name="id" value="{$domainid}">
                    <input type="hidden" name="sub" value="autorenew" />
                    {if $autorenew}
                        <input type="hidden" name="autorenew" value="disable">
                        <p class="text-center">
                            <button type="submit" class="btn btn-lg btn-danger">
                                {lang key='domainsautorenewdisable'}
                            </button>
                        </p>
                    {else}
                        <input type="hidden" name="autorenew" value="enable">
                        <p class="text-center">
                            <button type="submit" class="btn btn-lg btn-success">
                                {lang key='domainsautorenewenable'}
                            </button>
                        </p>
                    {/if}
                </form>

            </div>
        </div>

    </div>
    <div class="tab-pane fade" id="tabNameservers">

        <div class="card">
            <div class="card-body">

                <h3 class="card-title">{lang key='domainnameservers'}</h3>

                {if $nameservererror}
                    {include file="$template/includes/alert.tpl" type="error" msg=$nameservererror textcenter=true}
                {/if}
                {if $subaction eq "savens"}
                    {if $updatesuccess}
                        {include file="$template/includes/alert.tpl" type="success" msg="{lang key='changessavedsuccessfully'}" textcenter=true}
                    {elseif $error}
                        {include file="$template/includes/alert.tpl" type="error" msg=$error textcenter=true}
                    {/if}
                {/if}

                {include file="$template/includes/alert.tpl" type="info" msg="{lang key='domainnsexp'}"}

                <form role="form" method="post" action="{$smarty.server.PHP_SELF}?action=domaindetails#tabNameservers">
                    <input type="hidden" name="id" value="{$domainid}" />
                    <input type="hidden" name="sub" value="savens" />
                    <div class="form-check">
                        <label>
                            <input type="radio" class="form-check-input" name="nschoice" value="default" onclick="disableFields('domnsinputs',true)"{if $defaultns} checked{/if} /> {lang key='nschoicedefault'}
                        </label>
                    </div>
                    <div class="form-check mb-3">
                        <label>
                            <input type="radio" class="form-check-input" name="nschoice" value="custom" onclick="disableFields('domnsinputs',false)"{if !$defaultns} checked{/if} /> {lang key='nschoicecustom'}
                        </label>
                    </div>

                    {for $num=1 to 5}
                        <div class="form-group row">
                            <label for="inputNs{$num}" class="col-sm-4 col-form-label">{lang key='clientareanameserver'} {$num}</label>
                            <div class="col-md-7">
                                <input type="text" name="ns{$num}" class="form-control domnsinputs" id="inputNs{$num}" value="{$nameservers[$num].value}" />
                            </div>
                        </div>
                    {/for}

                    <div class="row">
                        <div class="col-sm-8 offset-sm-4">
                            <button type="submit" class="btn btn-primary">
                                {lang key='changenameservers'}
                            </button>
                        </div>
                    </div>
                </form>

            </div>
        </div>

    </div>
    <div class="tab-pane fade" id="tabReglock">

        <div class="card">
            <div class="card-body">

                <h3 class="card-title">{lang key='domainregistrarlock'}</h3>

                {if $subaction eq "savereglock"}
                    {if $updatesuccess}
                        {include file="$template/includes/alert.tpl" type="success" msg="{lang key='changessavedsuccessfully'}" textcenter=true}
                    {elseif $error}
                        {include file="$template/includes/alert.tpl" type="error" msg=$error textcenter=true}
                    {/if}
                {/if}

                {include file="$template/includes/alert.tpl" type="info" msg="{lang key='domainlockingexp'}"}

                <br />

                <h2 class="text-center">{lang key='domainreglockstatus'}: <span class="label label-{if $lockstatus == "locked"}success{else}danger{/if}">{if $lockstatus == "locked"}{lang key='domainsautorenewenabled'}{else}{lang key='domainsautorenewdisabled'}{/if}</span></h2>

                <br />
                <br />

                <form method="post" action="{$smarty.server.PHP_SELF}?action=domaindetails#tabReglock">
                    <input type="hidden" name="id" value="{$domainid}">
                    <input type="hidden" name="sub" value="savereglock" />
                    {if $lockstatus=="locked"}
                        <p class="text-center">
                            <button type="submit" class="btn btn-lg btn-danger">
                                {lang key='domainreglockdisable'}
                            </button>
                        </p>
                    {else}
                        <p class="text-center">
                            <button type="submit" class="btn btn-lg btn-success" name="reglock" value="1" />
                                {lang key='domainreglockenable'}
                            </button>
                        </p>
                    {/if}
                </form>

            </div>
        </div>

    </div>
    <div class="tab-pane fade" id="tabRelease">

        <div class="card">
            <div class="card-body">

                <h3 class="card-title">{lang key='domainrelease'}</h3>

                {if $releaseDomainSuccessful}
                    {include file="$template/includes/alert.tpl" type="success" msg="{lang key='changessavedsuccessfully'}" textcenter="true"}
                {elseif !empty($error)}
                    {include file="$template/includes/alert.tpl" type="error" msg="$error" textcenter="true"}
                {/if}

                {include file="$template/includes/alert.tpl" type="info" msg="{lang key='domainreleasedescription'}"}

                <form role="form" method="post" action="{$smarty.server.PHP_SELF}?action=domaindetails#tabRelease">
                    <input type="hidden" name="sub" value="releasedomain">
                    <input type="hidden" name="id" value="{$domainid}">

                    <div class="form-group row">
                        <label for="inputReleaseTag" class="col-4 col-form-label">{lang key='domainreleasetag'}</label>
                        <div class="col-6 col-sm-5">
                            <input type="text" class="form-control" id="inputReleaseTag" name="transtag" />
                        </div>
                    </div>

                    <p class="text-center">
                        <button type="submit" class="btn btn-primary">
                            {lang key='domainrelease'}
                        </button>
                    </p>
                </form>

            </div>
        </div>

    </div>
    <div class="tab-pane fade" id="tabAddons">

        <div class="card">
            <div class="card-body">
                <h3 class="card-title">{lang key='domainaddons'}</h3>

                <p>{lang key='domainaddonsinfo'}</p>

                <hr>

                {if $addons.idprotection}
                    <div class="row mb-3">
                        <div class="col-3 col-md-2 text-center">
                            <i class="fas fa-shield-alt fa-3x"></i>
                        </div>
                        <div class="col-9 col-md-10">
                            <strong>{lang key='domainidprotection'}</strong><br />
                            {lang key='domainaddonsidprotectioninfo'}<br />
                            <form action="clientarea.php?action=domainaddons" method="post">
                                <input type="hidden" name="id" value="{$domainid}"/>
                                {if $addonstatus.idprotection}
                                    <input type="hidden" name="disable" value="idprotect"/>
                                    <button type="submit" class="btn btn-danger">
                                        {lang key='disable'}
                                    </button>
                                {else}
                                    <input type="hidden" name="buy" value="idprotect"/>
                                    <button type="submit" class="btn btn-success">
                                        {lang key='domainaddonsbuynow'} {$addonspricing.idprotection}
                                    </button>
                                {/if}
                            </form>
                        </div>
                    </div>
                {/if}

                {if $addons.dnsmanagement}
                    <hr>
                    <div class="row margin-bottom">
                        <div class="col-3 col-md-2 text-center">
                            <i class="fas fa-cloud fa-3x"></i>
                        </div>
                        <div class="col-9 col-md-10">
                            <strong>{lang key='domainaddonsdnsmanagement'}</strong><br />
                            {lang key='domainaddonsdnsmanagementinfo'}<br />
                            <form action="clientarea.php?action=domainaddons" method="post">
                                <input type="hidden" name="id" value="{$domainid}"/>
                                {if $addonstatus.dnsmanagement}
                                    <input type="hidden" name="disable" value="dnsmanagement"/>
                                    <a class="btn btn-success" href="clientarea.php?action=domaindns&domainid={$domainid}">{lang key='manage'}</a>
                                    <button type="submit" class="btn btn-danger">
                                        {lang key='disable'}
                                    </button>
                                {else}
                                    <input type="hidden" name="buy" value="dnsmanagement"/>
                                    <button type="submit" class="btn btn-success">
                                        {lang key='domainaddonsbuynow'} {$addonspricing.dnsmanagement}
                                    </button>
                                {/if}
                            </form>
                        </div>
                    </div>
                {/if}

                {if $addons.emailforwarding}
                    <hr>
                    <div class="row mb-3">
                        <div class="col-3 col-md-2 text-center">
                            <i class="fas fa-envelope fa-3x">&nbsp;</i><i class="fas fa-share fa-2x"></i>
                        </div>
                        <div class="col-9 col-md-10">
                            <strong>{lang key='domainemailforwarding'}</strong><br />
                            {lang key='domainaddonsemailforwardinginfo'}<br />
                            <form action="clientarea.php?action=domainaddons" method="post">
                                <input type="hidden" name="id" value="{$domainid}"/>
                                {if $addonstatus.emailforwarding}
                                    <input type="hidden" name="disable" value="emailfwd"/>
                                    <a class="btn btn-success" href="clientarea.php?action=domainemailforwarding&domainid={$domainid}">{lang key='manage'}</a>
                                    <button type="submit" class="btn btn-danger">
                                        {lang key='disable'}
                                    </button>
                                {else}
                                    <input type="hidden" name="buy" value="emailfwd"/>
                                    <button type="submit" class="btn btn-success">
                                        {lang key='domainaddonsbuynow'} {$addonspricing.emailforwarding}
                                    </button>
                                {/if}
                            </form>
                        </div>
                    </div>
                {/if}

                <hr>

            </div>
        </div>
    </div>
</div>
