<html>
<head>
  <title>S.M.A.R.T detail of <%=dev%></title>
  <link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/cascade.css?v=v0.2.11" />
  <script type="text/javascript">//<![CDATA[
    let formData = new FormData()
    let xhr = new XMLHttpRequest()
    xhr.open("GET", '<%=luci.dispatcher.build_url("admin", "system", "diskman", "smartattr", dev)%>', true)
    xhr.onload = function () {
      let st = JSON.parse(xhr.responseText)
      let tb = document.getElementById('smart_attr_table');
      if (st && tb) {
        /* clear all rows */
        while (tb.rows.length > 1)
          tb.deleteRow(1);

        for (var i = 0; i < st.length; i++) {
          var tr = tb.insertRow(-1);
          tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
          var td = null
            <% if dev: match("nvme") then %>
              tr.insertCell(-1).innerHTML = st[i].key;
          tr.insertCell(-1).innerHTML = st[i].value;
            <% else %>
            tr.insertCell(-1).innerHTML = st[i].id;
          tr.insertCell(-1).innerHTML = st[i].attrbute;
          tr.insertCell(-1).innerHTML = st[i].flag;
          tr.insertCell(-1).innerHTML = st[i].value;
          tr.insertCell(-1).innerHTML = st[i].worst;
          tr.insertCell(-1).innerHTML = st[i].thresh;
          tr.insertCell(-1).innerHTML = st[i].type;
          tr.insertCell(-1).innerHTML = st[i].updated;
          tr.insertCell(-1).innerHTML = st[i].raw;
          if ((st[i].id == '05' || st[i].id == 'C5') && st[i].raw != '0') {
            tr.style.cssText = "background-color:red !important;";
          }
            <% end %>
          }
        if (tb.rows.length == 1) {
          var tr = tb.insertRow(-1);
          tr.className = 'cbi-section-table-row';
          var td = tr.insertCell(-1);
          td.colSpan = 4;
          td.innerHTML = '<em><br /><%:No Attrbute to display.%></em>';
        }
      }
    }
    xhr.send(formData)
    //]]></script>
</head>
<body>
  <div id="maincontainer">
    <fieldset class="cbi-section">
      <legend><%:S.M.A.R.T Attrbutes%>: /dev/<%=dev%></legend>
      <table class="cbi-section-table" id="smart_attr_table">
        <tr class="cbi-section-table-titles">
          <% if dev:match("nvme") then %>
          <!-- <th class="cbi-section-table-cell"><%:KEY%></th>
            <th class="cbi-section-table-cell"><%:VALUE%></th> -->
          <% else %>
          <th class="cbi-section-table-cell"><%:ID%></th>
          <th class="cbi-section-table-cell"><%:Attrbute%></th>
          <th class="cbi-section-table-cell"><%:Flag%></th>
          <th class="cbi-section-table-cell"><%:Value%></th>
          <th class="cbi-section-table-cell"><%:Worst%></th>
          <th class="cbi-section-table-cell"><%:Thresh%></th>
          <th class="cbi-section-table-cell"><%:Type%></th>
          <th class="cbi-section-table-cell"><%:Updated%></th>
          <th class="cbi-section-table-cell"><%:Raw%></th>
          <% end %>
        </tr>
        <tr class="cbi-section-table-row">
          <td colspan="4"><em><br /><%:Collecting data...%></em></td>
        </tr>
      </table>
    </fieldset>
  </div>
</body>
</html>