<?php

use common\models\OrderItems;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\date\DatePicker;
use unclead\widgets\MultipleInput;
use unclead\widgets\MultipleInputColumn;
/* @var $this yii\web\View */
/* @var $model common\models\Orders */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="orders-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'phone')->textInput(['maxlength' => true]) ?>

    <?php


    echo $form->field($model, 'delivery', [
    ])->radioList([
        '1' => 'Курьерска доставка по Киеву и области',
        '2' => 'В любой регион Украины',
        '3' => 'Самовывоз (бесплатно)',
    ], [
        'item' => function($index, $label, $name, $checked, $value) {

            $return = '<div><label class="modal-radio">';
            $return .=  Html::radio($name, $checked, ['value' => $value]);
            $return .= '<i></i>';
            $return .= '<span>' . ucwords($label) . '</span>';
            $return .= '</label></div>';

            return $return;
        },
    ]);


    ?>

    <?php


    echo $form->field($model, 'payment', [
    ])->radioList([
        '1' => 'Оплата наличными',
        '2' => 'Оплата по безналичному расчету. Код ЕГРПОУ',
        '3' => 'Приват 24',
        '4' => 'Согласовать с менеджером',
    ], [
        'item' => function ($index, $label, $name, $checked, $value) use ($model) {
            if($index != 1){

                $return = '<div><label class="modal-radio">';
                $return .= Html::radio($name, $checked, ['value' => $value]);
                $return .= '<i></i>';
                $return .= '<span>' . ucwords($label) . '</span>';
                $return .= '</label></div>';

                return $return;
            } else {

                $return = '<div><label class="modal-radio">';
                $return .= Html::radio($name, $checked, ['value' => $value]);
                $return .= '<i></i>';
                $return .= '<span>' . ucwords($label) . '</span>';
                $return .= Html::activeTextInput($model,'code');
                $return .= '</label></div>';

                return $return;
            }

        },
    ]);


    ?>

    <?= $form->field($model, 'status')->textInput() ?>

    <?= $form->field($model, 'created')->widget(DatePicker::classname(), [
        'language' => 'ru',
        'pluginOptions' => [
            'format'=> 'yyyy-mm-d'

        ],

    ]) ?>
    <?= $form->field($model, 'updated')->widget(DatePicker::classname(), [
        'language' => 'ru',
        'pluginOptions' => [
            'format'=> 'yyyy-mm-d'

        ],

    ]) ?>

    <?= $form->field($model, 'orderItems')->widget(MultipleInput::className(), [
        'columns' => [
            [
                'name'  => 'order_items_id',
                'type'  => MultipleInputColumn::TYPE_HIDDEN_INPUT,
            ],
            [
                'name'  => 'item_id',
                'type'  => MultipleInputColumn::TYPE_TEXT_INPUT,
                'title' => 'item id',
            ],
            [
                'name'  => 'item_name',
                'type'  => MultipleInputColumn::TYPE_TEXT_INPUT,
                'title' => 'name',
                'value' => function($data){
                    if($data instanceof OrderItems){
                        return $data->item->product->name .' '. $data->item->name;
                    }
                },
            ],
            [
                'name'  => 'item_count',
                'type'  => MultipleInputColumn::TYPE_TEXT_INPUT,
                'title' => 'item count',
            ],
            [
                'name'  => 'price',
                'type'  => MultipleInputColumn::TYPE_TEXT_INPUT,
                'title' => 'Price',
            ],
        ],
    ]);
    ?>



    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
