<%!
    title = 'Splunk Admin Server Control'
%>
<%namespace name="lib" file="//lib.html" import="*"/>
<%inherit file="//layout/admin.html"/>
<%
import splunk
from splunk.appserver.mrsparkle.lib import util, i18n

formattedExpirationDate = i18n.format_datetime(splunk.util.parseISO(licenseData.get("expirationDate",None)))
numberOfLicenseViolations = len(licenseData.get("licenseViolations", []))
secondsRemaining = int(licenseData.get("remainingTime",0))
daysRemaining = ((secondsRemaining / (24 * 3600)) + 1)
daysRemainingStr = _("expired") if (daysRemaining < 0) else str(daysRemaining) + ( _(" days") if (daysRemaining > 1) else _(" day") )
# both are in bytes... need to format to MB or something.
peakUsage = i18n.format_number( float( licenseData.get("peakIndexingThroughput", None) ) / 1048576)
licenseLevel = i18n.format_number( float( licenseData.get("licenseDailyUsageLimit", None) ) / 1048576)
licenseTypeStr = "Enterprise" if licenseData.get("licenseType", None) == "pro" else licenseData.get("licenseType", None)
%>
<div class="licenseWrapper">
    <div class="actionButtons">
        <a class="splButton-primary" href="${make_url(['manager', namespace, 'admin', 'license', 'license'])}?action=edit">
            <span>${_('Change license')}</span>
        </a>
    </div>
            
    <table class="splTable">
        <tr>
            <th colspan="4"><h1>${_('License &amp; usage')}</h1></th>
        </tr>
        % if licenseData:
        <tr class="datarow">
            <th>${_('Product:')}</th>
            <td>${licenseTypeStr | h}</td>
            <th>${_('Days remaining:')}</th>
            <td class="fourthTD">${daysRemainingStr | h}</td>
        </tr>
        <tr class="datarow">
            <th>${_('License level:')}</th>
            <td>${licenseLevel | h} MB</td>
            <th>${_('Peak usage:')}</th>
            <td>${peakUsage | h} MB</td>
        </tr>
        <tr class="datarow">
            <th>${_('Expiration date:')}</th>
            <td>${formattedExpirationDate | h}</td>
            <th>${_('License violations:')}</th>
            <td>
            % for violation in licenseData.get("licenseViolations", []):
                <%
                violationDate = violation.split(' ', 1)[0]
                violationString = violation.split(' ', 1)[1]
                %>
                ${violationString | h} at ${ i18n.format_datetime(splunk.util.parseISO(violationDate)) } <br/>
            % endfor
            </td>
        </tr>
        % else:
        <tr>
            <td colspan="5">${_('License data not returned')}</td>
        </tr>
        % endif
            
    </table>    
    <div style="border:1px solid #ddd;background-color:#f6f6f6;padding:5px;color:#666;margin-bottom:10px;">${callToAction}</div>

    <div style="border:1px solid #ddd;background-color:#f6f6f6;padding:5px;color:#666;margin-bottom:10px;">${_('NOTE: you can analyze your recent license usage in the <a href="%(url)s">indexing volume search view</a>.') % dict(url=make_url('/app/search/indexing_volume'))}</div>
</div>
