{**************************** 

RSThemes - Info
1. Alerts
    1.1. Addon Messages
    1.2. Extension Update Alert
    1.3. New Menu Version
    1.4. Integration Available
2. Information
    2.1. Theme Version
        2.1.1 Check If Stable Version
        2.1.2 New Version
        2.1.3 Compability
    2.2. Registration Date
    2.3. Next Due Date
    2.4. First Payment Amount
    2.5. Recurring Ammount
    2.6. Payment Method
    2.7. Support Access
        2.7.1 Access Expiring
        2.7.2 Access Expired
3. License Key
    3.1 License Form
    3.2 License Status
4. Sidebar

*****************************}


{extends file="adminarea/includes/layout.tpl"}

{block name="template-heading"}
    {include file="adminarea/includes/breadcrumb.tpl"} 
{/block}

{block name="template-tabs"}
    {include file="adminarea/includes/tabs.tpl"} 
{/block}

{block name="template-content"}
    <div class="block">

        {* 1. Alerts *}

        {* 1.1. Addon Messages *}
        {if $template->license()->getAddonMessages()}
            {$template->license()->getAddonMessages()}
        {/if}

        {if $isLagom2}

            {* 1.2. Extension Update Alert*}
            {foreach $extensionUpdate as $extensionUpdateAlert}
                {if $extensionUpdateAlert.extensionUpdateAllowed}
                <div class="alert alert--danger alert--outline has-icon alert--border-left alert--license" data-extension-update-alert>
                    <div class="alert__body">
                        <h6>Complete Update for {$extensionUpdateAlert.extensionName} Extension</h6>
                        <p>We have detected that new extension files have been uploaded. To finalize the update, a database records update is required from version <strong>{$extensionUpdateAlert.extensionCurrentVersion}</strong> to <strong>{$extensionUpdateAlert.extensionVersion}</strong>.</p>
                        <p>Click the button on the right to complete the installation process and ensure the extension functions correctly.</p>  
                    </div>
                    <div class="alert__actions">
                        <button type="button" 
                            data-extension-update-alert-btn
                            data-ajax-url="{$whmcsURL}/modules/addons/RSThemes/src/Api/adminApi.php?controller=ExtensionApi&method=extensionUpdate&extensionName={$extensionUpdateAlert.extension}"
                            data-btn-loader
                            class="btn btn--danger btn--outline btn--sm"
                        >
                            <span class="btn__preloader preloader"></span>
                            <span class="btn__text">Complete Update</span>
                        </button>
                    </div>
                </div>
                {else}
                    <div class="alert alert--danger alert--outline has-icon alert--border-left alert--license" data-extension-update-alert>
                        <div class="alert__body">
                            <h6>Incompatible Version of the {$extensionUpdateAlert.extensionName} Extension Detected</h6>
                            <p>
                                Your current version of Website Builder extension is not covered by your license, likely due to its expiration before version <strong>{$extensionUpdateAlert.extensionVersion}</strong> was released. To restore compatibility, please downgrade to a supported version or renew your license. For details, review our <a href="https://lagom.rsstudio.net/legal/terms-of-service/" target="_blank">Terms of Service</a> or <a href="https://rsstudio.net/my-account/submitticket.php?step=2&deptid=2">contact support</a>.
                            </p>
                        </div>
                        <div class="alert__actions">
                            <button type="button" 
                                data-extension-update-alert-btn-version-check
                                data-ajax-url="{$whmcsURL}/modules/addons/RSThemes/src/Api/adminApi.php?controller=ExtensionApi&method=extensionLicenseVersionAccessabilityReset&extensionName={$extensionUpdateAlert.extension}"
                                data-btn-loader
                                class="btn btn--danger btn--sm"
                            >
                                <span class="btn__preloader preloader preloader--light"></span>
                                <span class="btn__text">Verify Again</span>
                            </button>
                            <a 
                                href="https://lagom.rsstudio.net/docs/licensing/" 
                                target="_blank"
                                class="btn btn--default btn--outline btn--sm"
                            >
                                <span class="btn__text">Learn More</span>
                            </a>
                        </div>
                    </div>
                {/if}
            {/foreach}

            {* 1.3. New Menu Version *}
            {if $newChangedAnyMenuVersion}
                {include file="adminarea/includes/alert/newMenuImport.tpl"}
            {/if}

            {* 1.4. Integration Available *}
            {if isset($integrationAllowed) && $integrationAllowed}
                {include file="adminarea/includes/alert/integrationAvailable.tpl" integrationType=$integratonType}
            {/if}
        {/if}    

        <div class="block__body m-r-3x max-w-lg">

            {* 2. Information *}
            <div class="section">
                <h3 class="section__title">{$lang.info.theme_information.title}</h3>
                <div class="section__body panel">
                    <ul class="list list--info list--p-1x">

                        {* 2.1. Theme Version *}
                        <li class="list__item">
                            <span class="list__label">{$lang.info.theme_information.theme_version}:</span>
                            <span class="list__value">
                                <b>{$template->getVersion()}</b>  

                                {* 2.1.1 Check If Stable Version *}
                                {assign var="isStable" value=true}
                                {assign var="checkVersion" value="-"|explode:$template->getVersion()}
                                
                                {assign var="isNewVersionStable" value=true}
                                {assign var="checkNewVersion" value=$template->newVersion()|replace:"Lagom ":""}
                                {assign var="checkNewVersion" value="-"|explode:$checkNewVersion}

                                {if isset($checkNewVersion[1]) && $checkNewVersion[1] != ""}
                                    {assign var="isNewVersionStable" value=false}
                                {/if}

                                {if isset($checkVersion[1]) && $checkVersion[1] != ""}
                                    {assign var="isStable" value=false}
                                {/if}
                               
                                {* 2.1.2. New Version *}
                                {if $template->newVersionAvailable() && $isNewVersionStable && $isLagom2 && $compability === true}
                                    <span class="notification m-l-1x">
                                        <i class="notification__icon text-danger ls ls-exclamation-circle"></i> 
                                        <span class="notification__text text-danger">
                                            {$lang.info.theme_information.new_version} {*$template->newVersion()*}
                                        </span>
                                        {include 
                                            file="adminarea/includes/helpers/popover.tpl" 
                                            popoverClasses="notification__popover"
                                            popoverBody="{$lang.info.theme_information.new_version_desc}"
                                            popoverFooter="<a class='btn btn--secondary btn--xs' href='https://rsstudio.net/my-account/' target='_blank'>{$lang.general.download_now}</a>"
                                        }
                                    </span>
                                {/if}

                                {* 2.1.3. Compability *}
                                {if $compability === false && $isStable}
                                    <span class="notification m-l-1x">
                                        <i class="notification__icon text-danger ls ls-exclamation-circle"></i> 
                                        <span class="notification__text text-danger">
                                            {$lang.info.theme_information.incompatible_version}
                                        </span>
                                        {include 
                                            file="adminarea/includes/helpers/popover.tpl" 
                                            popoverClasses="notification__popover"
                                            popoverBody="<b>Lagom {$template->getVersion()}</b> {$lang.info.theme_information.incompatible_version_desc_1} <b>WHMCS {$whmcsVersion}</b> {$lang.info.theme_information.incompatible_version_desc_2}"
                                            popoverFooter="<a class='btn btn--secondary btn--xs' href='https://lagom.rsstudio.net/docs/common-problems/#i-m-using-incompatible-product-version' target='_blank'>{$lang.general.learn_more}</a>"
                                        }
                                    </span>
                                {/if}
                            </span>
                        </li>

                        {* 2.2. Registration Date *}
                        <li class="list__item">
                            <span class="list__label">{$lang.info.theme_information.registration_date}:</span>
                            <span class="list__value">{$template->license()->details('regdate')|date_format:"%A, %B %e, %Y"}</span>
                        </li>

                        {* 2.3. Next Due Date *}
                        <li class="list__item">
                            <span class="list__label">{$lang.info.theme_information.next_due_date}:</span>
                            <span class="list__value">
                                {if $template->license()->details('nextduedate')!='0000-00-00'}
                                    {$template->license()->details('nextduedate')|date_format:"%A, %B %e, %Y"}
                                {else}
                                    {$lang.info.theme_information.lifetime_license}
                                {/if}
                            </span>
                        </li>

                        {* 2.4. First Payment Amount *}
                        <li class="list__item">
                            <span class="list__label">{$lang.info.theme_information.first_payment}:</span>
                            <span class="list__value">
                                {$template->license()->details('first_payment_amount')}
                            </span>
                        </li>

                        {* 2.5. Recurring Amount *}
                        <li class="list__item">
                            <span class="list__label">{$lang.info.theme_information.recurring}:</span>
                            <span class="list__value">
                                {$template->license()->details('recuring_amount')}
                            </span>
                        </li>

                        {* 2.6. Payment Method *}
                        <li class="list__item">
                            <span class="list__label">{$lang.info.theme_information.payment_method}:</span>
                            <span class="list__value">
                                {$template->license()->details('payment_method')}
                            </span>
                        </li>

                        {* 2.7. Support Access *}
                        {if $template->license()->getLicenseKey() && $template->license()->details('service_status') == "Active"}
                            <li class="list__item">
                                <span class="list__label">{$lang.info.theme_information.support_access}:</span>
                                <span class="list__value d-flex">
                                    {if $template->license()->details('nextduedate')!='0000-00-00' && $template->license()->details('nextduedate')!=""}
                                        {assign var="hasNextDue" value=true}
                                        {assign var="diff" value=(strtotime($template->license()->details('nextduedate'))-strtotime('today'))/86400}
                                    {else}
                                        {assign var="hasNextDue" value=false}
                                        {assign var="diff" value=0}
                                    {/if}

                                    {if !$hasNextDue || $diff >= 0}
                                        <span class="label label--success label--outline">
                                            {$lang.general.active}
                                        </span>
                                    {else}
                                        <span class="label label--danger label--outline">
                                            {$lang.general.expired}
                                        </span>
                                    {/if}

                                    {* 2.7.1 / 2.7.2 — only for single licenses; for bundle the badge alone is enough *}
                                    {if !$template->license()->details('isBundlePackage')}
                                        {* 2.7.1 Access Expiring*}
                                        {if $hasNextDue && $diff >= 0 && $diff < 31}
                                            <span class="notification m-l-1x">
                                                <i class="notification__icon text-danger ls ls-exclamation-circle"></i>
                                                <span class="notification__text text-danger">
                                                    {if $diff == 0}
                                                        {$lang.general.expire_today}
                                                    {else}
                                                        {$lang.general.expire_in} {$diff} {if $diff == 1}{$lang.general.day}{else}{$lang.general.days}{/if}
                                                    {/if}
                                                </span>
                                                {include
                                                    file="adminarea/includes/helpers/popover.tpl"
                                                    popoverClasses="notification__popover"
                                                    popoverBody="<p>{$lang.info.theme_information.support_access_expire_desc}</p><p>{$lang.info.theme_information.support_access_pay_invoice}</p>"
                                                    popoverFooter="<a class='btn btn--secondary btn--xs' href='https://lagom.rsstudio.net/docs/common-problems.html#access-into-theme-updates-and-support-has-exired-or-expiring-soon' target='_blank'>{$lang.general.learn_more}</a>"
                                                }
                                            </span>

                                        {* 2.7.2 Access Expired *}
                                        {elseif $hasNextDue && $diff < 0}
                                            <span class="notification">
                                                {include
                                                    file="adminarea/includes/helpers/popover.tpl"
                                                    popoverClasses="notification__popover"
                                                    popoverBody="<p>{$lang.info.theme_information.support_access_expired_desc}</p><p>{$lang.info.theme_information.support_access_pay_invoice}</p>"
                                                    popoverFooter="<a class='btn btn--secondary btn--xs' href='https://lagom.rsstudio.net/docs/common-problems.html#access-into-theme-updates-and-support-has-exired-or-expiring-soon' target='_blank'>{$lang.general.learn_more}</a>"
                                                }
                                            </span>
                                        {/if}
                                    {/if}
                                </span>
                            </li>
                        {/if}
                    <ul>
                </div>
            </div>

            {* 3. License Key *}
            <div class="section">
                <h3 class="section__title">{$lang.info.license_key.title}</h3>
                <div class="section__body panel" data-license-container>   
                    
                    {* 3.1 License Form *}
                    <form data-license-form action="{$helper->url('Template@info',['templateName'=>$template->getMainName()])}" method="POST">
                        <div class="form-group d-flex w-100 gap-2x" data-license-form-group>
                            <div class="input-group input-group--lg flex-grow-1 is-readonly">
                                <span class="input-group__icon">
                                    <svg class="icon-gray" width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
                                        <g clip-path="url(#clip0_16979_4672)">
                                            <path fill-rule="evenodd" clip-rule="evenodd" d="M5.25 10.5C6.10009 10.5 6.90298 10.298 7.61329 9.93928L11.5257 13.8517L9.8339 15.5435C9.54101 15.8364 9.54101 16.3113 9.8339 16.6042L10.9952 17.7655C11.2881 18.0584 11.763 18.0584 12.0558 17.7655L13.7477 16.0736L15.3255 17.6515C15.6184 17.9443 16.0932 17.9443 16.3861 17.6515L17.6515 16.3861C17.9444 16.0932 17.9444 15.6183 17.6515 15.3254L9.9393 7.61323C10.298 6.90294 10.5 6.10006 10.5 5.25C10.5 2.35051 8.1495 0 5.25 0C2.35051 0 0 2.35051 0 5.25C0 8.1495 2.35051 10.5 5.25 10.5ZM5.25 7.5C6.49264 7.5 7.5 6.49264 7.5 5.25C7.5 4.00736 6.49264 3 5.25 3C4.00736 3 3 4.00736 3 5.25C3 6.49264 4.00736 7.5 5.25 7.5Z" fill="#B9BDC5"/>
                                        </g>
                                        <defs>
                                            <clipPath id="clip0_16979_4672">
                                                <rect width="18" height="18" fill="white"/>
                                            </clipPath>
                                        </defs>
                                    </svg>
                                </span>
                                <input 
                                    name="licenseKey" 
                                    class="form-control form-control--lg p-l-2x" 
                                    value="{if $template->license()->details('license_status') != ""}{$template->license()->getLicenseKey()}{/if}" 
                                    placeholder="" 
                                    readonly
                                    data-license-input="{if $template->license()->details('license_status') != ""}{$template->license()->getLicenseKey()}{/if}" 
                                    data-license-template="{if $template->isActive()}active{else}inactive{/if}"
                                    data-license-valid="{if $template->license()->getAddonMessages()}false{else}true{/if}"
                                > 
                            </div>
                            <button type="button" class="btn btn--lg btn--secondary"  data-toggle="lu-modal" data-target="#refreshLicense">
                                <span class="btn__text">
                                    Change License
                                </span>
                                <span class="btn__preloader preloader"></span>
                            </button>
                            <div class="form-feedback form-feedback--icon form-feedback-danger is-hidden" data-license-feedback>License cannot be empty!</div>
                        </div>
                        {if $template->license()->hasInputError()}
                            <div class="form-feedback form-feedback-lg form-feedback--icon {if $template->license()->details('status')|lower == "suspended"}form-feedback-danger{else}form-feedback-info{/if}">
                                <span>{$template->license()->getInputError()}</span>
                            </div>
                        {/if}
                    </form>    

                    {* 3.2 License Status *}        
                    {if $template->license()->getLicenseKey() && $template->license()->details('license_status') != ""}
                        <ul class="list list--info list--p-1x ">
                            <li class="list__item">
                                <span class="list__label">{$lang.info.license_key.license_status}:</span>
                                <span class="list__value">    
                                    <span class="label {if $template->license()->details('license_status') == "Active"}label--success{else}label--danger{/if} label--outline">{if $template->license()->details('license_status') == ""}Invalid{else}{$template->license()->details('license_status')}{/if}</span>
                                </span>
                            </li>                           
                        </ul>
                    {/if}
                </div>
            </div>
        </div>

        {* 4. Sidebar *}
        <div class="block__sidebar info-sidebar-block">
            <div class="widget widget--lg">
                <a class="widget__media has-overlay info-sidebar-widget">
                    {if $template->getVersion()|intval >= 2}
                        {include file="adminarea/info/includes/sidebar-logo-lagom-2.tpl"}
                    {else}
                        {include file="adminarea/info/includes/sidebar-logo-lagom.tpl"}
                    {/if}
                    {include file="adminarea/info/includes/sidebar-lines.tpl"}
                </a>
            </div>	
        </div>
    </div>    
{/block}

{block name="template-modals"}
    {include file="adminarea/includes/modals/license-modal.tpl"}
{/block}
