<%#
  Copyright (C) 2019  The Software Heritage developers
  See the AUTHORS file at the top-level directory of this distribution
  License: GNU Affero General Public License version 3, or any later version
  See top-level LICENSE file for more information
%>

<html>
  <head>
    <title>jslicense-labels1</title>
    <style>
      table, table td {
        vertical-align: top;
        white-space: nowrap;
      }
    </style>
  </head>
  <body>
    <h3>Web Labels</h3>
    <table id="jslicense-labels1" border="1">
      <thead>
        <tr>
          <th>Script</th>
          <th>Licenses</th>
          <th>Sources</th>
        </tr>
      </thead>
      <tbody>
        <% for (let jsasset of Object.keys(jslicenses_data).sort((a, b) => {
                  let va = a.split('/').slice(-1)[0];
                  let vb = b.split('/').slice(-1)[0];
                  if (va < vb) {
                    return -1
                  } else if (va > vb) {
                    return 1;
                  }
                  return 0;
                })) {
             let bundled_js_srcs = jslicenses_data[jsasset]; %>
          <tr>
            <td>
              <a href="<%= jsasset %>"><%= jsasset.split('/').slice(-1)[0] %></a>
            </td>
            <td>
              <% for (let i = 0; i < bundled_js_srcs.length ; ++i) {
                   let js_src = bundled_js_srcs[i];
                   for (let j = 0; j < js_src.licenses.length; ++j) {
                     let js_license = js_src.licenses[j]; %>
                     <a href="<%= js_license.url %>"><%= js_license.name %></a>
              <%     if (js_license.copy_url) { %>
                       (<a href="<%= js_license.copy_url %>">view</a>)
              <%     } %>
              <%     if (j != js_src.licenses.length - 1) {%>
                       <br/>
              <%     } %>
              <%   } %>
              <%   if (i != bundled_js_srcs.length - 1) {%>
                     <br/>
                     <hr/>
              <%   } %>
              <% } %>
            </td>
            <td>
              <% for (let i = 0; i < bundled_js_srcs.length ; ++i) {
                   let js_src = bundled_js_srcs[i]; %>
                   <a href="<%= js_src.src_url %>"><%= js_src.id %></a>
              <%   for (let j = 0 ; j < js_src.licenses.length - 1; ++j) { %>
                     <br/>
              <%   }%>
              <%   if (i != bundled_js_srcs.length - 1) {%>
                     <br/>
                     <hr/>
              <%   } %>
              <% } %>
            </td>
          </tr>
        <% } %>
      </tbody>
    </table>
  </body>
</html>