<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use frontend\components\HtmlHelper;
use kartik\widgets\DatePicker;
use common\models\Account;
use common\models\Transfer;
use common\components\Helper;

/* @var $this yii\web\View */
/* @var $model common\models\Ticket */
/* @var $accounts common\models\Account[] */
/* @var $ticketTypes common\models\TicketType[] */
/* @var $discounts common\models\Discount[] */
/* @var $form yii\widgets\ActiveForm */
?>

<?php 

	$accountOptions = [];
	$discountOptions= [];
	$ticketTypeOptions= [];
	
	$accountOptions = HtmlHelper::mkAccountOptions($accounts);
	$discountOptions =  ['' => ''] + HtmlHelper::mkDiscountOptions($discounts, [ 'emptyOption' => true] );
	$ticketTypeOptions = HtmlHelper::mkTicketTypeOptions($ticketTypes);

// 	echo "default kassza: " . Account::readDefault();
// 	echo "  kassza: " . $model->id_account;
	
?>

<div class="row" >
	<div class="col-md-12" >
		<div class="ticket-form">
		
		    <?php $form = ActiveForm::begin([
		    		'id' => 'ticket_form',
		    ]); ?>
		
		    <?= Html::activeHiddenInput($model, 'cart')?>
		    
		    <?= $form->field($model, 'id_ticket_type')->dropDownList($ticketTypeOptions) ?>
		
		    <?= $form->field($model, 'id_account')->dropDownList($accountOptions) ?>
		
			<?php echo $form->field($model,'payment_method')->dropDownList(Transfer::paymentMethods())  ?>
		
		    <?php  echo $form->field($model, 'id_discount')->dropDownList($discountOptions) ?>
		
		    <?= $form->field($model, 'start')->widget(DatePicker::classname(), [
		    			 'pluginOptions' => [
						        'autoclose'=>true,
						        'format' => 'yyyy.mm.dd'
						    ]
						])  ?>
		
		
			 <?= $form->field($model, 'end')->widget(DatePicker::classname(), [
		    			 'pluginOptions' => [
						        'autoclose'=>true,
						        'format' => 'yyyy.mm.dd'
						    ]
						])  ?>
		
		    <?= $form->field($model, 'max_usage_count')->input('number') ?>
		
		    <?php 
		    	if ( Helper::isTicketCreatePriceEditable()){
		    		echo $form->field($model, 'price_brutto')->input('number' );
		    	}else{
		    		echo $form->field($model, 'price_brutto')->input('number' ,['readonly' => true] );
		    		
		    	}
		    	
		    ?>
		
		    <?= $form->field($model, 'comment')->textarea(['maxlength' => true]) ?>
			
			<div class="row">
				<div class='col-md-4'>
					<?php echo Html::a(Yii::t("frontend/ticket","Fizetve"),null,['class' => 'btn btn-danger btn-block', 'id' => 'btn_sell'] );?>
				</div>
				<div class='col-md-4'>
					
					<?php 
						if ( Helper::isUserCartOn()){	
							echo Html::a(Yii::t("frontend/ticket","To cart"),null,['class' => 'btn btn-success btn-block', 'id' => 'btn_add_to_user_cart'] );
						}
					?>
				</div>
				<div class='col-md-4'>
					<?php 
						if ( $receptionForm->isCardWithCustomer() ){
							echo Html::a(Yii::t("frontend/ticket","Write up"),null,['class' => 'btn btn-success btn-block', 'id' => 'btn_add_to_customer_cart'] );
						}			
					?>
				</div>
			</div>
		    <?php ActiveForm::end(); ?>
		
		</div>
	</div>
</div>