<?php

use yii\helpers\Html;
use frontend\components\ReceptionMenuWidget;
use frontend\components\ReceptionCardNumberWidget;
use frontend\assets\TicketSellAsset;
use common\models\TicketType;
use yii\helpers\Url;
use frontend\components\ReceptionWidget;
use common\components\Helper;


/* @var $this yii\web\View */
/* @var $model common\models\Ticket */
/* @var $receptionForm frotned\models\ReceptionForm */

$card = $receptionForm->card;
$customer = $receptionForm->customer;

TicketSellAsset::register($this);

$this->title = Yii::t('common/ticket', 'Create Ticket');
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/ticket', 'Tickets'), 'url' => ['index' , 'number' => $card->number ]];
$this->params['breadcrumbs'][] = $this->title;


$options = [];

// $options['lookup_product_url'] = Url::toRoute(['product/lookup']);
$options['clear_cart_url'] = Url::toRoute(['product/clear-list']);
$options['types'] = TicketType::modelsToArray($ticketTypes);
$options['user_cart'] = $model->userCart;
// $options['customer_cart'] = $model->customerCart;
$options['selected_type'] = count($ticketTypes) > 0 ? $ticketTypes[0]->id_ticket_type : 0;
$options['url_delete_transaction'] = Url::toRoute(['transfer/delete']);
$options['url_pay_transaction'] = Url::toRoute(['transfer/payout']);
$options['url_pay_user_cart'] = Url::toRoute(['product/payout-user-cart' , 'number' =>isset($receptionForm->card) ? $receptionForm->card->number : '']);

if ( isset($receptionForm->card) ){
	$options['url_pay_customer_card'] = Url::toRoute(['product/payout-customer-cart','number' => $receptionForm->card->number]);
	$options['customer_cart'] = $model->customerCart;
}

$discountItems = [];
foreach ($discounts as $d){
	$item = [];
	$item['id_discount'] = $d->id_discount;
	$item['value'] = $d->value;
	$discountItems[] = $item;
}
$options['discounts'] = $discountItems;

$this->registerJs ( 'new TicketSell( '. json_encode($options).');' );
?>
<div class="ticket-create">
	<?php echo ReceptionWidget::widget( ['form' => $receptionForm, 'route' => ['customer/reception'] ] )?>
	<div class="row">
		<div class="col-md-6">
		    <h1><?= Html::encode($this->title) ?></h1>
		    <?= $this->render('_form', [
		        'model' => $model,
		    		'discounts' => $discounts,
		    		'ticketTypes' => $ticketTypes,
		    		'accounts' => $accounts,
		    		'receptionForm' => $receptionForm,
		    ]) ?>
		</div>
		<div class='col-md-6'>
			<?php if (  $receptionForm->isCardWithCustomer()  ){ ?>
				<?php echo $this->render('_customer_cart' ,['model' => $receptionForm]) ?>
			<?php }?>
			<?php 
			if ( Helper::isUserCartOn() ) { 
			  echo $this->render('_user_cart' ) ;
			}
		   ?>
		</div>
	</div>
</div>
