<?php
    use common\models\Basket;
    use common\models\Orders;
    use common\modules\product\models\ProductVariant;
    use yii\helpers\Html;
    use yii\helpers\Url;
    use yii\web\View;
    use yii\widgets\ActiveForm;
    use yii\widgets\MaskedInput;
    
    /**
     * @var View             $this
     * @var ProductVariant[] $models
     * @var Basket           $basket
     */
?>
<div class="modal-dialog buy-product" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
            <div class="modal-title" id="myModalLabel">
                <div class="h3">
                    <span class="cart-icon"></span>
                    <a href="#"><span class="cart_count"><?php echo $basket->getCount(); ?></span> товар(ов)</a>
                    на сумму
                    <span class="cart_total"><?php echo $basket->getSum(); ?></span><span class="currency">&nbsp;<!--грн.--></span>
                </div>
            </div>
        </div>
        <div class="modal-body">
            <table class="tovar">
                <tbody>
                <?php
                    foreach($models as $model) {
                        ?>
                        <tr data-id="<?php echo $model->product_variant_id; ?>">
                            <td class="left">
                                <?php
                                    echo Html::img($model->getImageUrl());
                                ?>
                            </td>
                            <td class="right">
                                <div class="title"><?php echo $model->getFullname(); ?></div>
                                <div class="count_choise">
                                    <span class="minus"></span>
                                    <input type="text" name="count" value="<?php echo $basket->getItem($model->product_variant_id)[ 'count' ]; ?>" class="prod_count">
                                    <span class="plus"></span>
                                    <span class="total_summ">= <span class="total_prod">
                                            <?php
                                                $item = $basket->getItem($model->product_variant_id);
                                                echo $item[ 'count' ] * $item[ 'price' ];
                                            ?>
                                        </span><span class="currency">&nbsp;<!--грн.--></span>
                                    </span>
                                    <span class="cart_remove">x</span>
                                </div>
                                <input type="hidden" name="prod_id" value="" id="prod_id">
                            </td>
                        </tr>
                        <?php
                    }
                ?>
                <tr>
                    <td class="left">
                        <?= Html::a('Оформить заказ', Url::to('/order/main'), [ 'class' => 'btn' ]) ?>
                    
                    </td>
                    <td class="right">
                        <div class="back_to_shop">
                            <a data-dismiss="modal" aria-label="Close" href="javascript:false">продолжить покупки</a>
                        </div>
                        <p class="rettext">товар сохранится в корзине</p>
                    </td>
                </tr>
                </tbody>
            </table>
            <br/>
        </div>
        <div class="modal-footer">
            <div class="gray_part" id="buy_back_call_form">
                <p class="title">Заказать без оформления</p>
                <p class="subtitle">Можно не заполнять никаких форм, просто оставить телефон и консультант решит все вопросы по оформлению заказа.</p>
                <div class="back_call_form">
                    <?php
                        $quickbuy = new Orders([
                            'scenario' => Orders::SCENARIO_QUICK,
                        ]);
                        $form = ActiveForm::begin([
                            'id' => 'quickbuy-modal',
                        ]);
                        echo $form->field($quickbuy, 'phone', [
                            'selectors' => [
                                'input' => '#order-phone-modal',
                            ],
                        ])
                                  ->widget(MaskedInput::className(), [
                                      'mask'    => '+38(999)999-99-99',
                                      'options' => [
                                          'type'  => 'tel',
                                          'class' => 'customerphone',
                                          'id'    => 'order-phone-modal',
                                      ],
                                  ])
                                  ->label(false);
                        echo Html::submitInput('жду звонка', [ 'class' => 'btn btn-info' ]);
                        echo Html::tag('span', '', [
                            'class' => 'submit_indicator',
                        ]);
                        $form::end();
                    ?>
                    <div class="clr"></div>
                </div>
                <p class="phone-example">например: +38 (095) 282-85-08</p>
            </div>
        
        </div>
    
    </div>
</div>