<% include ../header %>
<script type="text/javascript">document.getElementById("adiciona").classList.value = "active"</script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
  $( "#datepicker" ).datepicker({
  dateFormat: "dd/mm/yy"
});
} );
</script>
<div class='erros'>
     <%if(errosValidacao){%>
        <ul>
            <%for(var i=0;i<errosValidacao.length;i++){%>
                <li><%=errosValidacao[i].param%> - <%=errosValidacao[i].msg%></li>
            <%}%>
        </ul>
     <%}%>
</div>
<div class="container">
  <form action="/equipamentos" method="post">
  <%
    var idDoEquip = (equipamentos[0] && equipamentos[0].id);
    var nomeDoEquip = (equipamentos[0] && equipamentos[0].nome);
    if (equipamentos[0] && equipamentos[0].dtmanut && true){
      var datamanut = equipamentos[i].dtmanut.toISOString().replace(/(\d{4})-(\d{2})-(\d{2})[^\r\n]*/, '$3/$2/$1');
      var edita = true;
    }
    agora = new Date().toISOString().replace(/(\d{4})-(\d{2})-(\d{2})[^\r\n]*/, '$3/$2/$1');
  %>
    <div class="form-group" hidden>
      <input type="text" id="id" name="id" value="<%=idDoEquip%>"/>
    </div>
    <div class="form-group">
        <label class="form-check-label" for="nome">Nome:</label>
        <input class="form-control" type="text" id="nome" name="nome" value="<%=nomeDoEquip%>" placeholder="Nobreak Cliente"/>
    </div>
    <div class="form-group">
        <label class="form-check-label" for="dtmanut">Data da Próxima Manutenção:</label>
        <input class="form-control" type="text" id="datepicker" name="dtmanut" value="<%=datamanut%>" placeholder="XX/XX/XXXX"/>
    </div>
    <div class="form-group" hidden>
        <label class="form-check-label" for="dtult"></label>
        <input class="form-control" type="text" id="dtult" name="dtult" value="<%=agora%>" placeholder="XX/XX/XXXX"/>
    </div>
      <%if (edita) { %>
        <div class="form-group" hidden>
            <input class="form-control" type="text" id="tipo" name="tipo" value="editar"/>
        </div>
        <input class="btn btn-primary" type="submit" value="Editar"/>
      <%}else{%>
        <div class="form-group" hidden>
            <input class="form-control" type="text" id="tipo" name="tipo" value="salvar"/>
        </div>
        <input class="btn btn-primary" type="submit" value="Salvar"/>
      <%}%>

</form>
</div>
<% include ../footer %>
