[%- PROCESS "statistics/macros-header.tt" -%]

[%- MACRO entry(entity, type) BLOCK -%]
<tr class="[% loop.parity %]">
  <td class="t">[% loop.count %]</td>
  [% IF type == 'lang' %]
    <td>[% entity.entity.l_name || l('Unknown language') %]</td>
    <td class="t">
      [%- link_searchable_property(type, entity.entity.iso_code_3 || 'unknown', 'release', add_commas(entity.releases)) -%]</td>
    <td class="t">
      [%- link_searchable_property(type, entity.entity.iso_code_3 || 'unknown', 'work', add_commas(entity.works)) -%]</td>
    <td class="t">[% add_commas(entity.total) %]</td>
  [% ELSIF type == 'script' %]
    <td>[% entity.entity.l_name || l('Unknown script') %]</td>
    <td class="t">
      [%- link_searchable_property(type, entity.entity.iso_code || 'unknown', 'release', add_commas(entity.count)) -%]</td>
  [% END %]
</tr>
[%- END -%]

[% WRAPPER 'statistics/layout.tt' title=l('Languages and Scripts') full_width=1 page='languages-scripts' %]

<p>[%- l('Last updated: {date}', { date => date_collected }) -%]</p>
<p>[%- l('All other available languages and scripts have 0 releases and works.') -%]</p>

<div style="float:left; display:inline-block; margin-right: 50px;">
  <h2 style="margin-top:0;">[%- l('Languages') -%]</h2>
  <table class="tbl" id="languages-table">
    <thead>
      <tr>
        <th class="pos">[% l('Rank') %]</th>
        <th>[% l('Language') %]<div class="arrow"></div></th>
        <th>[% l('Releases') %]<div class="arrow"></div></th>
        <th>[% l('Works') %]<div class="arrow"></div></th>
        <th>[% l('Total') %]<div class="arrow"></div></th>
      </tr>
    </thead>
    <tbody>
      [%- FOREACH language IN language_stats -%]
        [% NEXT IF language.count == 0 %]
        [%- entry(language, 'lang') -%]
      [%- END -%]
    </tbody>
  </table>
</div>

<div style="float:left; display:inline-block;">
  <h2 style="margin-top:0;">[%- l('Scripts') -%]</h2>
  <table class="tbl" id="scripts-table">
    <thead>
      <tr>
        <th class="pos">[% l('Rank') %]</th>
        <th>[% l('Script') %]<div class="arrow"></div></th>
        <th>[% l('Releases') %]<div class="arrow"></div></th>
      </tr>
    </thead>
    <tbody>
      [%- FOREACH script IN script_stats -%]
        [% NEXT IF script.count == 0 %]
        [%- entry(script, 'script') -%]
      [%- END -%]
    </tbody>
  </table>
</div>
[%- PROCESS "statistics/macros-footer.tt" -%]

[%- script_manifest('statistics.js') -%]

<script type="text/javascript">//<![CDATA[
  $('#languages-table').tablesorter({
      widgets: [ 'indexFirstColumn', 'evenRowClasses' ],
      headers: { 0: {sorter: false}, 2: { sorter: 'fancyNumber' }, 3: { sorter: 'fancyNumber' }, 4: { sorter: 'fancyNumber' } },
      sortList: [ [4,1], [1,0] ] // order by descending number of entities, then name
  });
  $('#scripts-table').tablesorter({
      widgets: [ 'indexFirstColumn', 'evenRowClasses' ],
      headers: { 0: {sorter: false}, 2: { sorter: 'fancyNumber' } },
      sortList: [ [2,1], [1,0] ] // order by descending number of entities, then name
  });
//]]></script>

[% END %]
