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

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

<body id="page-top">
  <!-- Page Wrapper -->
  <div id="wrapper">

    <!-- Sidebar -->
    <%- include('../../tools/sidebarTec'); %>
    <!-- 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">Inscribir Establecimiento</h1>
                  </div>
                  <form onsubmit="hvForm(event)" action="/tecnico/HojaVida/InscribirHV" method="POST" autocomplete="off">

                    <div class="form-row align-items-center mb-sm-2">
                      <div class="col my-1">
                        <label class="mr-sm-2" for="provinciaID">Provincia</label>
                        <input type="text" class="form-control form-control-user" id="provinciaID" name="provincia" value="<%= user.provincia %>" readonly>
                      </div>
                      <div class="col my-1">
                        <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>
                          <option value="<%= user.municipio %>">
                            <%= user.municipio %>
                          </option>
                          <% if(user.municipioExtra1 !="" ){ %>
                          <option value="<%= user.municipioExtra1 %>">
                            <%= user.municipioExtra1 %>
                          </option>
                          <% } %>
                          <% if(user.municipioExtra2 !="" ){ %>
                          <option value="<%= user.municipioExtra2 %>">
                            <%= user.municipioExtra2 %>
                          </option>
                          <% } %>
                          <% if(user.municipioExtra3 !="" ){ %>
                          <option value="<%= user.municipioExtra3 %>">
                            <%= user.municipioExtra3 %>
                          </option>
                          <% } %>
                        </select>
                      </div>
                    </div>

                    <div class="form-group row">
                      <div class="col-sm-8 mb-3 mb-sm-0">
                        <label class="mr-sm-2" for="grupEsta">Grupo Del
                          Establecimiento</label>
                        <select id="grupEsta" name="grupEsta" class="custom-select mr-sm-2">
                          <option selected disabled>
                            Seleccione el Grupo
                          </option>
                          <% var numberSelected2="" ; %>
                          <% if(codigos){ %>
                          <% codigos.forEach((codigos)=> { %>
                          <% if (numberSelected2 !=codigos.grupo){ %>
                          <option value="<%= codigos.grupo %>">
                            <%= codigos.grupo %>
                          </option>
                          <% numberSelected2=codigos.grupo %>
                          <% } %>
                          <% }) %>
                          <% } %>
                        </select>
                      </div>
                      <div class="col-sm-4">
                        <label class="mr-sm-2" for="Nriesgo">Nivel de Riesgo</label>
                        <input type="text" class="form-control form-control-user" id="Nriesgo" name="Nriesgo" placeholder="Ninguno" readonly />
                      </div>
                    </div>

                    <div class="form-group row">
                      <div class="col-sm-12">
                        <label class="mr-sm-2" for="tipoEsta">Tipo Del
                          Establecimiento</label>
                        <select id="tipoEsta" name="tipoEsta" class="custom-select mr-sm-2">
                          <option selected>Seleccione el Tipo
                          </option>
                        </select>
                      </div>
                    </div>

                    <div class="form-group row">
                      <div class="col-sm-3">
                        <label class="mr-sm-2" for="codEsta">Codigo
                          Establecimiento</label>
                        <input type="text" class="form-control form-control-user" id="codEsta" name="codEsta" placeholder="Ninguno" readonly />
                      </div>
                      <div class="col-sm-3">
                        <label class="mr-sm-2" for="tIden">Tipo de
                          Identificación</label>
                        <select id="tIden" name="tIden" class="custom-select mr-sm-2">
                          <option selected disabled>Seleccione</option>
                          <option>Cedula Ciudadania</option>
                          <option>NIT</option>
                        </select>
                      </div>
                      <div class="col-sm-3">
                        <label class="mr-sm-2" for="inputIden">Identificación</label>
                        <input type="number" class="form-control form-control-user" id="inputIden" name="inputIden" />
                      </div>
                      <div class="col-sm-3">
                        <label class="mr-sm-2" for="phone">Telefono</label>
                        <input type="number" class="form-control form-control-user" id="phone" name="phone" />
                      </div>
                    </div>

                    <div class="form-group row">
                      <div class="col-sm-4">
                        <label class="mr-sm-2" for="rSocial">Razón Social</label>
                        <input type="text" class="form-control form-control-user" id="rSocial" name="rSocial" onkeyup="mayus(this);" />
                      </div>
                      <div class="col-sm-4">
                        <label class="mr-sm-2" for="idenSocial">Codigo Inscripción</label>
                        <input type="text" class="form-control form-control-user" id="idenSocial" name="idenSocial" />
                      </div>
                      <div class="col-sm-4">
                        <label class="mr-sm-2" for="direccion">Dirección</label>
                        <input type="text" class="form-control form-control-user" id="direccion" name="direccion" onkeyup="mayus(this);" />
                      </div>
                    </div>

                    <div class="form-group row">
                      <div class="col-sm-6">
                        <label class="mr-sm-2" for="rLegal">Representante Legal</label>
                        <input type="text" class="form-control form-control-user" onkeyup="mayus(this);" id="rLegal" name="rLegal" />
                      </div>
                      <div class="col-sm-2" id="placaDiv" style="display: none;">
                        <label class="mr-sm-2" for="placa">Placa</label>
                        <input type="text" class="form-control form-control-user" onkeyup="mayus(this);" id="placa" name="placa" />
                      </div>
                      <div class="col-sm-4">
                        <label class="mr-sm-2" for="estado">Estado</label>
                        <select id="estado" name="estado" class="custom-select mr-sm-2">
                          <option selected disabled>Seleccione el Estado</option>
                          <option value="EN FUNCIONAMIENTO">EN FUNCIONAMIENTO
                          </option>
                          <option value="CON MEDIDA SANITARIA">CON MEDIDA SANITARIA
                          </option>
                          <option value="CERRADO">CERRADO</option>
                        </select>
                      </div>
                    </div>

                    <div class="form-group row">
                      <div class="col-sm-4">
                        <label class="mr-sm-2" for="iDueno">Identificación Dueño (Opcional)</label>
                        <input type="number" class="form-control form-control-user" id="iDueno" name="iDueno" onkeyup="mayus(this);" />
                      </div>
                      <div class="col-sm-8">
                        <label class="mr-sm-2" for="nDueno">Nombre Dueño (Opcional)</label>
                        <input type="text" class="form-control form-control-user" id="nDueno" name="nDueno" onkeyup="mayus(this);" />
                      </div>
                    </div>


                    <button class="btn btn-primary btn-user btn-block" type="submit">
                      Registrar Establecimiento
                    </button>
                  </form>

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

          <script type="text/JavaScript">
            const arrayCod = []
        <% if(codigos){ %>
            <% codigos.forEach((codigos)=> { %>
                arrayCod.push(["<%= codigos.grupo %>"], ["<%= codigos.codigo %>"], ["<%= codigos.tipo %>"], ["<%= codigos.nivelRiesgo %>"])
            <% }) %>
        <% } %>
        </script>

        </div>
        <!-- /.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="/tecnico/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/formularios.js"></script>
  <script type="text/JavaScript" src="/js/tools/codigoEsta.js"></script>

  <!-- Alert -->
  <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>

  <script>
    $(window).bind('load', function() {
      var nav = document.getElementById('nav3');
      $('#navlink2').removeClass('collapsed');
      var nav3 = document.getElementById('collapseThree');
      var nav4 = document.getElementById('show4');
      nav.className += "  active";
      nav3.className += "  show";
      nav4.className += "  active";
    });

    $("#grupEsta").change(function() {
      if (document.getElementById("grupEsta").value == "VEHÍCULOS TRANSPORTADORES DE ALIMENTOS Y BEBIDAS") {
        document.getElementById("placaDiv").removeAttribute("style")
      } else {
        document.getElementById("placaDiv").style.display = "none"
      }
    });
  </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>