<?php
  if( $_POST['action'] == 'New' ){
    $Val = $_POST['val'];
    $Action = 'New';

    $Position     = '../../';
    require_once($Position.'config/config.php');
    require_once($Position.'config/conexion.php');

  }elseif( $Action == 'Edit' ){
    $Val = $Variante[Id];
    $Action = 'Edit';
  }
?>

<div class="ItemOpc">
  <div
    class="card"
    style="
      position: relative;
    "
  >

    <!-- Btn -->
    <button
      class="btn btn-danger DelItemOpc"
      type="button"
      style="
        position: absolute;
        top: 0px;
        right: 0px;
      "
    >
      <i class="fa fa-times"></i>
    </button>
    <!-- End Btn -->

    <div class="card-body">
      <div class="row">

        <input
          type="hidden"
          name="Variantes[]"
          value="<?php echo $Val; ?>"
        />

        <!-- Id -->
        <input
          type="hidden"
          name="Variante[<?php echo $Val; ?>][Id]"
          value="<?php echo $Val; ?>"
        />
        <!-- End Id -->

        <!-- Action -->
        <input
          type="hidden"
          name="Variante[<?php echo $Val; ?>][Action]"
          value="<?php echo $Action; ?>"
        />
        <!-- End Action -->

        <!-- Clave -->
        <div class="col-sm-3 form-group">
          <label>Clave</label>
          <input
            name="Variante[<?php echo $Val; ?>][Clave]"
            class="form-control text-left"
            data-required="true"
            value="<?php echo $Variante[Clave]; ?>"
            autocomplete="off"
          />
        </div>
        <!-- End Clave -->

        <!-- Unidad de Medida -->
        <div class="col-sm-3 form-group">
          <label>Unidad de Medida</label>
          <select
            name="Variante[<?php echo $Val; ?>][Medida]"
            class="form-control chosen-select"
          >
            <option value="0">Sin unidad de medida</option>
            <?php
              //Medidas
              $Query = "
                SELECT
                  me.Id, me.Clave, me.Nombre
                FROM CatalogoMedidas me
                WHERE me.Id != '0'
                ORDER BY me.Nombre ASC
              ";
              $Medidas = $mysqli->query($Query);
              mysqli_data_seek($Medidas, 0);
              while($Medida = mysqli_fetch_array($Medidas)) {
            ?>
              <option
                <?php
                  if( $Variante[Fk_Medida] == $Medida[Id] ){
                    echo "selected='selected'";
                  }
                ?>
                value="<?php echo $Medida[Id]; ?>"
              >
                <?php echo $Medida[Clave].' - '.$Medida[Nombre]; ?>
              </option>
            <?php } ?>
          </select>
        </div>
        <!-- End Unidad de Medida -->

        <!-- Alto -->
        <div class="col-sm-2 form-group">
          <label>Alto</label>
          <input
            name="Variante[<?php echo $Val; ?>][Alto]"
            class="form-control text-right"
            dara-type="number"
            value="<?php echo $Variante[Alto]; ?>"
            autocomplete="off"
          />
        </div>
        <!-- End Alto -->

        <!-- Ancho -->
        <div class="col-sm-2 form-group">
          <label>Ancho</label>
          <input
            name="Variante[<?php echo $Val; ?>][Ancho]"
            class="form-control text-right"
            dara-type="number"
            value="<?php echo $Variante[Ancho]; ?>"
            autocomplete="off"
          />
        </div>
        <!-- End Ancho -->

        <!-- Largo -->
        <div class="col-sm-2 form-group">
          <label>Largo</label>
          <input
            name="Variante[<?php echo $Val; ?>][Largo]"
            class="form-control text-right"
            dara-type="number"
            value="<?php echo $Variante[Largo]; ?>"
            autocomplete="off"
          />
        </div>
        <!-- End Largo -->

        <!-- Talla -->
        <div class="col-sm-3 form-group">
          <label>Talla</label>
          <select
            name="Variante[<?php echo $Val; ?>][Talla]"
            class="form-control chosen-select"
          >
            <option value="0">Sin talla</option>
            <?php
              //Tallas
              $Query = "
                SELECT
                  ta.Id, ta.Clave, ta.Nombre
                FROM CatalogoTallas ta
                WHERE ta.Id != '0'
                ORDER BY ta.Nombre ASC
              ";
              $Tallas = $mysqli->query($Query);
              mysqli_data_seek($Tallas, 0);
              while($Talla = mysqli_fetch_array($Tallas)) {
            ?>
              <option
                <?php
                  if( $Variante[Fk_Talla] == $Talla[Id] ){
                    echo "selected='selected'";
                  }
                ?>
                value="<?php echo $Talla[Id]; ?>"
              >
                <?php echo $Talla[Clave].' - '.$Talla[Nombre]; ?>
              </option>
            <?php } ?>
          </select>
        </div>
        <!-- End Talla -->

        <!-- Color -->
        <div class="col-sm-3 form-group">
          <label>Color</label>
          <select
            name="Variante[<?php echo $Val; ?>][Color]"
            class="form-control chosen-select"
          >
            <option value="0">Sin color</option>
            <?php
              //Colores
              $Query = "
                SELECT
                  col.Id, col.Nombre
                FROM Colores col
                WHERE col.Id != '0'
                ORDER BY col.Nombre ASC
              ";
              $Colores = $mysqli->query($Query);
              mysqli_data_seek($Colores, 0);
              while($Color = mysqli_fetch_array($Colores)) {
            ?>
              <option
                <?php
                  if( $Variante[Fk_Color] == $Color[Id] ){
                    echo "selected='selected'";
                  }
                ?>
                value="<?php echo $Color[Id]; ?>"
              >
                <?php echo $Color[Nombre]; ?>
              </option>
            <?php } ?>
          </select>
        </div>
        <!-- End Color -->

        <!-- Existencia -->
        <div class="col-sm-2 form-group">
          <label>Existencia</label>
          <input
            name="Variante[<?php echo $Val; ?>][Existencia]"
            class="form-control text-right"
            dara-type="number"
            value="<?php echo $Variante[Existencia]; ?>"
            autocomplete="off"
          />
        </div>
        <!-- End Existencia -->

        <!-- Peso -->
        <div class="col-sm-2 form-group">
          <label>Peso</label>
          <input
            name="Variante[<?php echo $Val; ?>][Peso]"
            class="form-control text-right"
            dara-type="number"
            value="<?php echo $Variante[Peso]; ?>"
            autocomplete="off"
          />
        </div>
        <!-- End Peso -->

        <!-- PesoMedida -->
        <div class="col-sm-2 form-group">
          <label>Medida de Peso</label>
          <select
            name="Variante[<?php echo $Val; ?>][PesoMedida]"
            class="form-control chosen-select"
          >
            <?php
              //PesoMedida
              $Query = "
                SELECT
                  me.Id, me.Medida, me.Clave
                FROM CatalogoPesoMedidas me
                ORDER BY me.Clave ASC
              ";
              $MedidasPeso = $mysqli->query($Query);
              mysqli_data_seek($MedidasPeso, 0);
              while($MedidaPeso = mysqli_fetch_array($MedidasPeso)) {
            ?>
              <option
                <?php
                  if( $Variante[Fk_PesoMedida] == $MedidaPeso[Id] ){
                    echo "selected='selected'";
                  }
                ?>
                value="<?php echo $MedidaPeso[Id]; ?>"
              >
                <?php echo $MedidaPeso[Clave].' - '.$MedidaPeso[Medida]; ?>
              </option>
            <?php } ?>
          </select>
        </div>
        <!-- End PesoMedida -->

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