<? if (!$this->giftcards->count()) : ?>
	No results found
<? else : ?>
	<table class="table table-normal">
		<thead>
			<td>Date</td>
			<td>Code</td>
			<td>Value</td>
			<td>Restaurant</td>
			<td>User</td>
			<td>Phone</td>
			<td>Email</td>
			<td>Note</td>
			<td>Issued as</td>
			<td>Group</td>
			<td>Redeemed</td>
		</thead>
		<? foreach ($this->giftcards as $giftcard) : ?>
			<? 
				$date = $giftcard->date(); 
				$wasUsed = CrunchButton_Promo::giftWasAlreadyUsed( $giftcard->id_promo );
			?>
			<tr class="<?=strtolower($giftcard->type); ?>">
				<td> <?=$date->format('M jS Y')?><br /><?=$date->format('g:i:s A')?> </td>
				<td style="width:70px;"> 
					<?php if( !$wasUsed ) { ?>
						<a title="Print" target="_blank" href="/giftcards/print/<?=$giftcard->id_promo;?>"><i style="color:black;" class="icon-print"></i></a>&nbsp;
						<a title="Print Flyer" target="_blank" href="/giftcards/print-flyer/<?=$giftcard->id_promo;?>"><i style="color:black;" class="icon-picture"></i></a>&nbsp;
						<a title="Print Brown Gift Card" target="_blank" href="/giftcards/print-brown/<?=$giftcard->id_promo;?>"><i style="color:black;" class="icon-flag"></i></a>
					<?php } ?> <a href="/giftcards/<?=$giftcard->id_promo;?>"><?=$giftcard->code; ?></a>
				</td>
				<td class="center"> $<?= Util::ceil($giftcard->value, 2); ?></td>
				<td class="center"> <? if( $giftcard->id_restaurant ){ echo $giftcard->restaurant()->name; } else { echo 'Any Restaurant'; } ?> </td>
				<td> <? if( $giftcard->user()->name != '' ){ echo $giftcard->user()->name; } else { echo '-'; } ?> </td>
				<td> <? if( $giftcard->phone ){ echo $giftcard->phone; } else { echo '-'; } ?> </td>
				<td> <? if( $giftcard->email ){ echo $giftcard->email; } else { echo '-'; } ?> </td>
				<td> <?=nl2br( $giftcard->note ); ?> </td>
				<td class="center"> 
					<? if ( $giftcard->issued == Promo::ISSUED_CREDIT ){ ?>
						<i class="icon-money"></i> Credit
					<?php } elseif ( $giftcard->issued == Promo::ISSUED_TEXT ){ ?>
						<i class="icon-mobile-phone"></i> Text
					<?php } elseif ( $giftcard->issued == Promo::ISSUED_EMAIL ){ ?>
						<i class="icon-envelope"></i> Email
					<?php } elseif ( $giftcard->issued == Promo::ISSUED_PRINT ){ ?>
						<i class="icon-print"></i> Paper (print)
					<?php } else { ?> - <?php } ?>
				</td>
				<td>
					<?php 
						$groups = $giftcard->groups(); 
						if( $groups->count() > 0 ){
							$commas = '';
							foreach ( $groups as $group ) {
								echo $commas . $group->name ;
								$commas = ', ';
							}
						} else {
							echo '-';
						}
					?>
				</td>
				<td class="center"> 
					<?php if( $wasUsed ) { ?>
						<span class="badge badge-green">Redeemed</span>
					<?php } else { ?>
						<span class="badge badge-black">Not redeemed</span>
					<?php } ?>
				</td>
			</tr>
		<? endforeach ; ?>
	</table>
<? endif ; ?>