<?php
// customer / cockpit and drivers will see the value with the markup #2369
$isDriverCockpit = ( $cockpit || $this->cockpit_url );

$order->dishes();

$restaurant = $order->restaurant();

$paymentType = $order->paymentType();

$icon = '';
if( $isDriverCockpit ){
	if( $version == 'restaurant' ){
		$icon = 'restaurant';
	} else if( $version == 'customer' ){
		$icon = 'customer';
	} else {
		$icon = 'driver';
	}
} else {
	if( $user ){
		$icon = 'customer';
	} else {
		$icon = 'restaurant';
	}
}
?>
<div class="xhatch separator-big"></div>

<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<td style="border: 0; padding: 5px;">
			<h1 title="<?php echo $order->id_restaurant == 1 ? 'One Button Wenzel' : 'Crunchbutton'; ?>"><?php echo $order->id_restaurant == 1 ? 'One Button Wenzel' : 'Crunchbutton'; ?></h1>
		</td>
		<td style="border: 0; padding: 5px; text-align: right;">
			<span class="order-num">Order #<?php echo $order->id_order; ?></span><br />
			<?php echo $order->date()->format('M jS, h:i a'); ?>
		</td>
	</tr>
</table>

<div class="xhatch separator-small"></div>

<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<td>
			<?php if ($order->delivery_type == 'delivery') { ?>
				<table cellpadding="0" cellspacing="0"><tr>
					<td><img src="<?php echo $this->helper('ImageBase64')->output(c::config()->dirs->www.'assets/images/mprinter/delivery.png'); ?>" class="icon-big"></td>
					<td class="text-size-mid">
						<?php if( $icon == 'restaurant' && $restaurant->delivery_service && $restaurant->formal_relationship ) { ?>
							Order for Crunchbutton Pickup
						<?php } else { ?>
							Order for Delivery
						<?php } ?>
					</td>
				</tr></table>
			<?php } else { ?>
				<table cellpadding="0" cellspacing="0"><tr>

					<td><img src="<?php echo $this->helper('ImageBase64')->output(c::config()->dirs->www.'assets/images/mprinter/takeout.png'); ?>" class="icon-big"></td>
					<td class="text-size-mid">Order for Takeout</td>
				</tr></table>
			<?php } ?>
		</td>
		<td>
			<?php if ($order->pay_type == 'card') { ?>
				<table cellpadding="0" cellspacing="0"><tr>
					<td><img src="<?php echo $this->helper('ImageBase64')->output(c::config()->dirs->www.'/assets/images/mprinter/card.png'); ?>" class="icon-big"></td>
					<td class="text-size-mid">
					Prepaid by&nbsp;
					<?php if( $paymentType->card_type == Crunchbutton_User_Payment_Type::CARD_TYPE_CAMPUS_CASH ) {
						echo $order->campusCashName();
						if( $order->requireSignature() ){
							echo '<br>Card: ' . $order->campusCashLastDigits();
						}
					 } else {
					 	echo 'card';
					 } ?>
					</td>
				</tr></table>
			<?php } else { ?>
				<table cellpadding="0" cellspacing="0"><tr>
					<td><img src="<?php echo $this->helper('ImageBase64')->output(c::config()->dirs->www.'/assets/images/mprinter/cash.png'); ?>" class="icon-big"></td>
					<td class="text-size-mid">Cash order</td>
				</tr></table>
			<?php } ?>
		</td>
		<?php // Change print receipt #4692
		/* ?>
		<td>
			<table cellpadding="0" cellspacing="0"><tr>
				<td><img src="<?php echo $this->helper('ImageBase64')->output(c::config()->dirs->www.'/assets/images/mprinter/timer.png'); ?>" class="icon-big"></td>
				<td class="text-size-mid">
						<?php if( $icon == 'restaurant' && $restaurant->delivery_service && $restaurant->formal_relationship ) { ?>
							Make food, we'll pick it up!
						<?php } else { ?>
							Estimated by <?php
							$estimated_by = $order->restaurant()->calc_delivery_estimated_time( $order->date()->format( 'Y-m-d H:i:s' ), true );
							echo $estimated_by->format('h:i'); ?>
						<?php } ?>
						</td>
			</tr></table>
		</td>
		<?php */ ?>
	</tr>
</table>




<?php if ($order->notes) { ?>
	<div class="xhatch separator-small"></div>

	<table class="notes" cellpadding="0" cellspacing="0">
		<tr>
			<td valign="top"><img src="<?php echo $this->helper('ImageBase64')->output(c::config()->dirs->www.'/assets/images/mprinter/note.png'); ?>" class="icon-note"></td>
			<td style="margin: 0; padding: 22px 0 0 0;" valign="top"><div class="arrow-left"></div></td>
			<td style="width: 100%; padding-right: 0; "><table style="width: 100%"><tr><td class="notes-content"><?php echo nl2br($order->notes); ?></td></tr></table></td>
		</tr>
	</table>
<?php } ?>

<div class="xhatch separator-small"></div>


<table width="100%" celpadding="0" cellspacing="0">
	<tr>
		<td style="width: 50%">
			<table cellpadding="0" cellspacing="0"><tr>
				<td><img src="<?php echo $this->helper('ImageBase64')->output(c::config()->dirs->www.'/assets/images/mprinter/customer.png'); ?>" class="icon-big"></td>
				<td class="text-size-mid"><?php echo $order->name; ?><br />
				<?php echo $order->phone(); ?>
				</td>
			</tr></table>
		</td>
		<td>
			<table cellpadding="0" cellspacing="0"><tr>
				<td><img src="<?php echo $this->helper('ImageBase64')->output(c::config()->dirs->www.'/assets/images/mprinter/restaurant.png'); ?>" class="icon-big"></td>
				<td class="text-size-mid"><?php echo $order->restaurant()->name; ?><br />
				<?php // Change print receipt #4692
				/*
					<?php echo $order->restaurant()->phone; ?>
				*/
				?>
				</td>
			</tr></table>
		</td>
	</tr>
	<tr>
		<td style="width: 50%">
			<?php if ($order->delivery_type == 'delivery') { ?>
				<table cellpadding="0" cellspacing="0"><tr>
					<td><img src="<?php echo $this->helper('ImageBase64')->output(c::config()->dirs->www.'/assets/images/mprinter/map.png'); ?>" class="icon-big"></td>
					<td class="text-size-mid"><?php echo nl2br(strip_tags($order->address)); ?></td>
				</tr></table>
			<?php }  ?>
		</td>
		<td style="width: 50%">
			<?php if ($order->_print && $order->delivery_type == 'takeout') { ?>
				<table cellpadding="0" cellspacing="0"><tr>
					<td><img src="<?php echo $this->helper('ImageBase64')->output(c::config()->dirs->www.'/assets/images/mprinter/map.png'); ?>" class="icon-big"></td>
					<td class="text-size-mid"><?php echo nl2br(strip_tags($order->restaurant()->address)); ?></td>
				</tr></table>
			<?php } ?>
		</td>
	</tr>

</table>
<?php
if( $this->cockpit_url ){
	// https://github.com/crunchbutton/crunchbutton/issues/2463#issue-28386594
?>
	<div class="xhatch separator-small"></div>
	<table width="100%" celpadding="0" cellspacing="0">
		<tr>
			<td width="50%" class="text-size-mid center">
				<strong><?php echo $order->driverInstructionsFoodStatus(); ?></strong>
			</td>
			<td width="50%" class="text-size-mid center">
				<strong><?php echo $order->driverInstructionsPaymentStatus(); ?></strong>
			</td>
		</tr>
	</table>
<?php } ?>
<div class="xhatch separator-small"></div>

<?php echo $this->render('order/details',['set' => ['order' => $order, 'user' => $user, 'isDriverCockpit' => $isDriverCockpit, 'version' => $version, 'viewer' => $icon, 'show_credit_card_tips' => $show_credit_card_tips, 'show_delivery_fees' => $show_delivery_fees ]]);

;?>
<br /><br />
<?php if (!$signature && !$order->_print) { ?>
	<table cellpadding="0" cellspacing="0" style="width: 100%; margin-top: 20px;">
		<tr>
			<td style="text-align: left;" class="text-size-small"><?php  if ($order->pay_type == 'card') { ?>Card on file. Signature not required.<?php } ?></td>
			<td style="text-align: right;" class="text-size-small">Crunchbutton support: call or text <?php echo c::config()->phone->restaurant; ?></td>
		</tr>
	</table>
<?php } ?>


<?php
/* Link to reps */
if( $this->cockpit_url ) { ?>
	<table cellpadding="0" cellspacing="0" style="width: 100%; margin-top: 20px;">
		<tr>
			<td style="text-align: left; font-weight:bold;" class="text-size-small">Visit: <a style="color:#000;" target="_blank" href="<?php echo $this->cockpit_url; ?>"><?php echo $this->cockpit_url; ?></a></td>
		</tr>
	</table>
<?php } ?>

<?php if( $signature ) {
	echo $this->display('order/signature',[ 'set' => ['order' => $order ] ]);
}?>

<?php
/* Crunchbutton's info */
if( $order->campus_cash ) { ?>
	<table cellpadding="0" cellspacing="0" style="width: 100%; margin-top: 20px;">
		<tr>
			<td style="text-align: left; font-weight:bold;" class="text-size-small"><?php echo nl2br( $order->campusCashReceiptInfo() ); ?></td>
		</tr>
	</table>
<?php } ?>

<div class="xhatch separator-big" style="text-align:right!important;">
<?php if( $icon != '' ) { ?>
	<img style="margin:4px 4px 0 0" src="<?php echo $this->helper('ImageBase64')->output(c::config()->dirs->www.'/assets/images/mprinter/ico-'. $icon . '.png'); ?>">
<?php } ?>
</div>

<?php if (!$user && $order->restaurant()->customer_receipt) { ?>
	<br /><br />
	<div style="border-top: 1px dashed black"> </div>
	<br /><br />

	<h2 align="center">Customer Copy</h2>
	<br /><br />
	<h1 style="text-align: center"><?php echo $order->restaurant()->name; ?></h1>
	<br /><br />
	<?php echo $this->display('order/details',['set' => ['order' => $order]]); ?>
<?php } ?>

<?php if ($order->_print) { ?>
<script>window.print();</script>
<?php } ?>
