<!DOCTYPE html>
<html lang="es">

<head>
  <%- include('../../tools/head'); %>
</head>

<body id="page-top">
  <!-- Page Wrapper -->
  <div id="wrapper">
    <!-- Sidebar -->
    <%- include('../../tools/sidebarAdmin'); %>
      <!-- End of Sidebar -->

      <!-- Content Wrapper -->
      <div id="content-wrapper" class="d-flex flex-column">
        <!-- Main Content -->
        <div id="content">
          <!-- Topbar -->
          <%- include('../../tools/topbar'); %>
            <!-- End of Topbar -->

            <!-- Begin Page Content -->
            <div class="container-fluid">
              <!-- Page Heading -->
              <div class="container">
                <div class="card o-hidden border-0 shadow-lg my-5">
                  <div class="card-body p-0">
                    <!-- Nested Row within Card Body -->
                    <div class="p-5">
                      <div class="text-center">
                        <h1 class="h4 text-gray-900 mb-4">Crea una Cuenta</h1>
                      </div>
                      <form onsubmit="registerForm(event)" action="/coordinacion/Cuentas/Register" method="POST"
                        autocomplete="off">

                        <div class="form-group row">
                          <div class="col-sm-6 mb-3 mb-sm-0">
                            <input type="text" class="form-control form-control-user" id="name" name="name"
                              onkeyup="mayus(this);" placeholder="Nombre(s)" autocomplete="off" />
                          </div>
                          <div class="col-sm-6">
                            <input type="text" class="form-control form-control-user" id="lastname"
                              onkeyup="mayus(this);" name="lastname" placeholder="Apellido(s)" autocomplete="off" />
                          </div>
                        </div>

                        <div class="form-group">
                          <input placeholder="Numero de Identificación" type="number"
                            class="form-control form-control-user" id="user" name="user" autocomplete="false"
                            minlegth="8" maxlength="10" />
                        </div>

                        <div class="form-group row">
                          <div class="col-sm-6 mb-3 mb-sm-0">
                            <input type="password" class="form-control form-control-user" id="pass" name="pass"
                              placeholder="Contraseña" autocomplete="off" minlength="4" maxlength="10" />
                          </div>
                          <div class="col-sm-6">
                            <input type="password" class="form-control form-control-user" id="repass" name="repass"
                              placeholder="Repite la Contraseña" autocomplete="off" minlength="4" maxlength="10" />
                          </div>
                        </div>

                        <div class="form-group row ">
                          <div class="col-sm-4">
                            <label class="mr-sm-2" for="provinciaID">Provincia</label>
                            <select id="provinciaID" name="provincia" class="custom-select mr-sm-2">
                              <option selected disabled>Seleccione la Provincia</option>
                              <% let numberSelected="" ; %>
                                <% if(fields){ %>
                                  <% fields.forEach((fields)=> { %>
                                    <% if (numberSelected !=fields.provincia){ %>
                                      <option value="<%= fields.provincia %>">
                                        <%= fields.provincia %>
                                      </option>
                                      <% numberSelected=fields.provincia %>
                                        <% } %>
                                          <% }) %>
                                            <% } %>

                            </select>
                          </div>
                          <div class="col-sm-4">
                            <label class="mr-sm-2" for="muniSelect">Municipio</label>
                            <select id="muniSelect" name="municipio" class="custom-select mr-sm-2">
                              <option selected disabled>Seleccione el Municipio</option>
                            </select>
                          </div>
                          <div class="col-sm-4">
                            <label class="mr-sm-2" for="rol">Rol</label>
                            <select class="custom-select mr-sm-2" id="rol" name="rol">
                              <option selected disabled>Seleccione el Rol</option>
                              <option value="coordinacion">Coordinación</option>
                              <option value="profesional">Profesional</option>
                              <option value="tecnico">Tecnico</option>
                            </select>
                          </div>
                        </div>

                        <button id="btnregis" class="btn btn-primary btn-user btn-block" type="submit">
                          Registrar Cuenta
                        </button>

                      </form>
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <script type="text/JavaScript">
            const array = []
            <% if(fields){ %>
            <% fields.forEach((fields)=> { %>
              array.push(["<%= fields.provincia %>"], ["<%= fields.municipio %>"])
            <% }) %>
            <% } %>
          </script>

            <!-- /.container-fluid -->
        </div>
        <!-- End of Main Content -->

        <!-- Footer -->
        <%- include('../../tools/footer'); %>
          <!-- End of Footer -->
      </div>
      <!-- End of Content Wrapper -->
  </div>
  <!-- End of Page Wrapper -->

  <!-- Scroll to Top Button-->
  <a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
  </a>

  <!-- Logout Modal-->
  <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
    aria-hidden="true">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLabel">Salida</h5>
          <button class="close" type="button" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">×</span>
          </button>
        </div>
        <div class="modal-body">
          Seleccione "Cerrar sesión" a continuación si está listo para
          finalizar su sesión actual.
        </div>
        <div class="modal-footer">
          <button class="btn btn-secondary" type="button" data-dismiss="modal">
            Cancelar
          </button>
          <a class="btn btn-primary" href="/coordinacion/logout">Cerrar Sesión</a>
        </div>
      </div>
    </div>
  </div>

  <!-- Bootstrap core JavaScript-->
  <script src="/vendor/jquery/jquery.min.js"></script>
  <script src="/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <!-- Core plugin JavaScript-->
  <script src="/vendor/jquery-easing/jquery.easing.min.js"></script>
  <!-- Custom scripts for all pages-->
  <script src="/js/sb-admin-2.min.js"></script>
  <!-- Validations -->
  <script type="text/javascript" src="/js/Coordinador/validaciones.js"></script>
  <script type="text/javascript" src="/js/Coordinador/formularios.js"></script>
  <!-- Alert -->
  <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>

  <script type="text/JavaScript">
    $(window).bind("load", function () {
      var nav = document.getElementById("nav4");
      $("#navlink3").removeClass("collapsed");
      var nav3 = document.getElementById("collapsePages");
      var nav4 = document.getElementById("show6");
      nav.className += "  active";
      nav3.className += "  show";
      nav4.className += "  active";
    });
    </script>
  <% if(typeof alert !="undefined" ) { %>
    <script type="text/JavaScript">
          Swal.fire({
            title: '<%= alert[0].alertTitle %>',
            text:'<%= alert[0].alertMessage %>',
            icon:'<%= alert[0].alertIcon %>',
            showConfirmButton: <%= alert[0].showConfirmButton %>,
            timer: <%= alert[0].timer %>
          }).then(()=>{
            window.location = '/<%= alert[0].ruta %>'
          })
        </script>
    <% } %>


</body>

</html>