<ul class="list-group">
    <li class="list-group-item">
        <div class="row filtros-giftcards mini-labels">
            <div class="col-12 col-md-4">
                <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#modalGiftcardForm" data-id="0"><i class="fas fa-plus"></i> Nueva GiftCard</h4>
            </div>
        </div>
    </li>
    <li class="list-group-item">
        <div class="table-responsive">
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th class="text-center">ID</th>
                        <th class="text-center">Venta PS</th>
                        <th class="text-center">ID Venta</th>
                        <th class="text-center">Tipo</th>
						<th>Destinatario</th>
                        <th class="text-center">Monto</th>
                        <th class="text-center">ID Cupón</th>
                        <th class="text-center">Estado</th>
                        <th class="text-center">Fecha Envío</th>
                        <th class="text-center">Activa</th>
                        <th class="text-center">Cant Disp</th>
						<th class="text-center">Uso</th>
                        <th class="text-center">Fecha Uso</th>
                        <th style="min-width: 130px;">Acciones</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    if (!empty($giftcards)) {
                        foreach($giftcards as $g) {
                            /*
                            $classEstado = 'badge-info';
                            if ($g['estado'] == 1) {
                                $classEstado = 'badge-success';
                            }*/
                            ?>
                            <tr id="giftcard<?php echo $g['id']; ?>">
                                <td class="text-center"><?php echo $g['id']; ?></td>
                                <td class="text-center"><?php echo $g['id_venta_ps']; ?></td>
                                <td class="text-center"><?php echo $g['id_venta']; ?></td>
								<td>
									<?php
									echo ($g['id_tipo'] == 1) 
										? 'Normal' 
										: (($g['id_tipo'] == 2) ? 'Navideña' : '');
									?>
								</td>
                                <td><?php echo $g['nombre_destinatario']; ?></td>
                                <td class="text-center"><?php echo clp($g['monto']); ?></td>
                                <td class="text-center"><?php echo $g['id_cupon']; ?></td>
                                <td class="text-center"><?php echo $estados_giftcards[$g['estado']]; ?></td>
                                <td class="text-center"><?php echo fechaHora($g['fecha_envio']); ?></td>

                                <td class="text-center">
                                    <?php
                                        $active = 'fa-check text-success';
                                        if ($g['active'] == 0) {
                                            $active = 'fa-times text-danger';
                                        }
                                        ?>
                                        <i class="fas <?php echo $active; ?>"></i>
                                </td>
                                <td class="text-center"><?php echo $g['quantity']; ?></td>
								
                                <td class="text-center">
                                    <?php
                                    if (!empty($g['id_order'])) { 
                                        ?>
                                        <span class="ps-id badge badge-pill badge-primary" data-toggle="tooltip" title="Ver en PS" data-ps-id="<?php echo $g['id_order']; ?>">
                                            <?php echo $g['id_order']; ?>
                                        </span>
                                    <?php 
                                    }
                                    ?>
                                </td>
                                <td class="text-center">
                                    <?php
                                    if (!empty($g['date_add'])) { 
                                        echo fechaHora($g['date_add']);
                                    }
                                    ?>
                                </td>

                                <td>
                                    <button type="button" class="btn btn-primary btn-sm tt" title="Editar" data-toggle="modal" data-target="#modalGiftcardForm" data-id="<?php echo $g['id']; ?>">
                                        <i class="fas fa-pencil-alt"></i>
                                    </button>
                                    <?php

									if ($g['estado'] == 1 && $g['email_destinatario'] != '' && $g['id_tipo'] == 1) {
                                    	echo '<span class="send-giftcard" data-toggle="modal" data-target="#modalEnvioGiftcard" data-id="'. $g['id'] .'">';
                                    	echo '<i class="fas fa-envelope"></i>';
                                    	echo '</span>';
									}
									if ($g['estado'] == 2 && $g['email_destinatario'] != '' && $g['id_tipo'] == 1) {
                                    	echo '<button type="button" class="btn btn-warning btn-sm send-giftcard clickable" data-toggle="modal" data-target="#modalEnvioGiftcard" data-id="'. $g['id'] .'">';
                                    	echo 'Reenviar';
                                    	echo '</button>';
									}

									/* Solo activar para navidad y validar imágenes */
									if ($g['estado'] == 1 && $g['email_destinatario'] != '' && $g['id_tipo'] == 2) {
                                    	echo '<span class="send-giftcard" data-toggle="modal" style="color: #FF0000" data-target="#modalEnvioGiftcardNavidad" data-id="'. $g['id'] .'">';
                                    	echo '<i class="fas fa-envelope"></i>';
                                    	echo '</span>';
									}
									if ($g['estado'] == 2 && $g['email_destinatario'] != '' && $g['id_tipo'] == 2) {
										echo '<button type="button" class="btn btn-warning btn-sm send-giftcard clickable" data-toggle="modal" data-target="#modalEnvioGiftcardNavidad" data-id="'. $g['id'] .'">';
                                    	echo 'Reenviar';
                                    	echo '</button>';
									}
									
                                    /*
                                    if ($g['estado_traspaso'] == 4) {
                                        ?>
                                        <button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#modalGiftcardForm" data-id="<?php echo $g['id']; ?>" data-action="ver">
                                            <i class="fas fa-eye"></i>
                                        </button>
                                    <?php
                                    }
                                    else {
                                        ?>
                                            <button type="button" class="btn btn-primary btn-sm tt" title="Editar" data-toggle="modal" data-target="#modalGiftcardForm" data-id="<?php echo $g['id']; ?>">
                                                <i class="fas fa-pencil-alt"></i>
                                            </button>
                                            <button type="button" class="btn btn-primary btn-sm tt" title="Completar" data-toggle="modal" data-target="#modalGiftcardForm" data-id="<?php echo $g['id']; ?>" data-action="completar">
                                                <i class="fas fa-check"></i>
                                            </button>
                                        <?php
                                    }
                                    ?>
                                    <a href="/giftcards/imprimir/<?php echo $g['id']; ?>" target="_blank" class="btn btn-info btn-sm"><i class="fas fa-print"></i></a>
                                    */ ?>
                                </td>
                            </tr>
                        <?php
                        }
                    }
                    else {
                        echo '<tr><td colspan="9" class="text-center">No hay Giftcards</td></tr>';
                    }
                    ?>
                </tbody>
            </table>
        </div>
    </li>
</ul>

<div class="modal fade" id="modalEnvioGiftcard" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="sendGiftcard" aria-hidden="true">
  <div class="modal-dialog modal-xl" role="document">
    <div class="modal-content">
      <div class="modal-wait">
        <div class="modal-header">
          <h5 class="modal-title" id="editVentaLabel">Enviar Giftcard</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <?php
            $this->load->view('giftcards/envio');
          ?>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
          <button type="button" class="btn btn-primary" id="enviarGiftcard">Enviar</button>
        </div>
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="modalEnvioGiftcardNavidad" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="sendGiftcardNavidad" aria-hidden="true">
  <div class="modal-dialog modal-xl" role="document">
    <div class="modal-content">
      <div class="modal-wait">
        <div class="modal-header">
          <h5 class="modal-title" id="editVentaLabel">Enviar Giftcard Navideña</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
		<div id="envio-giftcard-navidad">
			<input type="hidden" name="id" id="idGiftcardEnviarNavidad" />
		</div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
          <button type="button" class="btn btn-primary" id="enviarGiftcardNavidad">Enviar</button>
        </div>
      </div>
    </div>
  </div>
</div>

<?php $this->load->view('giftcards/form'); ?>
<script src="<?php echo js('giftcards.js'); ?>"></script>