<?php
use dosamigos\chartjs\ChartJs;
use yii\helpers\Html;
use \yii\widgets\ActiveForm;
use \kartik\date\DatePicker;
?>

<div class="auctions-index">
    <div class="panel panel-primary">
        <div class="panel-heading"><span class="glyphicon glyphicon-th-large"></span><strong> <?= Html::encode($this->title) ?></strong></div>
        <div class="panel-body">
            <p>
                <?=Yii::t('app', 'Total count - {count}', ['count' => $total])?>
            </p>
            <?php $form = ActiveForm::begin([
                'method' => 'get',
            ]); ?>

            <div class="row">
                <div class="col-xs-6">
                    <?= $form->field($searchModel, 'month')->widget(DatePicker::className(),[
                        'removeButton' => false,
                        'pluginOptions' => [
                            'autoclose'=>true,
                            'format' => 'yyyy.mm',
                            'viewMode' => 'months',
                            'minViewMode' => "months",
                            'locale' => [ 'format' => 'yyyy.mm', 'dateFormat' => 'yy-mm-dd', ]
                        ],
                    ])->label(false); ?>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <?= Html::submitButton(Yii::t('app', 'Confirm'), ['class' => 'btn btn-primary'])?>
                    </div>
                </div>
            </div>

            <?php ActiveForm::end(); ?>
            <div class="row">
                <div class="col-xs-12">
                    <h2><?= Yii::t('app', 'Registered users per month'); ?></h2>
                    <?= ChartJs::widget([
                        'type' => 'line',
                        'options' => [
                            'height' => 70,
                        ],
                        'clientOptions' => [
                            'scales' => [
                                'yAxes' => [[
                                    'ticks' => [
                                        'stepSize' => 1
                                    ]
                                ]]
                            ]
                        ],
                        'data' => [
                            'labels' => fillCount(countDayInMonth($searchModel)),
                            'datasets' => [
                                [
                                    'label' => Yii::t('app', 'Selected month'),
                                    'backgroundColor' => "rgba(179,181,198,0.2)",
                                    'borderColor' => "rgba(179,181,198,1)",
                                    'pointBackgroundColor' => "rgba(179,181,198,1)",
                                    'pointBorderColor' => "#fff",
                                    'pointHoverBackgroundColor' => "#fff",
                                    'pointHoverBorderColor' => "rgba(179,181,198,1)",
                                    'data' => $users
                                ],
                            ]
                        ]
                    ]); ?>
                    <hr>
                </div>
                <div class="col-xs-12">
                    <h2><?= Yii::t('app', 'Auctions by status per month'); ?></h2>
                    <?= ChartJs::widget([
                        'type' => 'line',
                        'options' => [
                            'height' => 70,
                        ],
                        'clientOptions' => [
                            'scales' => [
                                'yAxes' => [[
                                    'ticks' => [
                                        'stepSize' => 1
                                    ]
                                ]]
                            ]
                        ],
                        'data' => [
                            'labels' => fillCount(countDayInMonth($searchModel)),
                            'datasets' => $auctions

                        ]
                    ]); ?>
                    <hr>
                </div>
            </div>

            <div class="row">
                <div class="col-xs-12">
                    <hr>
                </div>
                <div class="col-md-6">
                    <h2><?= Yii::t('app', 'Auctions by category'); ?></h2>
                    <?= ChartJs::widget([
                        'type' => 'pie',
                        'options' => [
                            'height' => 90,
                        ],
                        'clientOptions' => [
                            'legend' => [
                                'position' => 'left'
                            ]
                        ],
                        'data' => [
                            'labels' => $categories['labels'],
                            'datasets' => [
                                [
                                    'data' => $categories['data'],
                                    'backgroundColor' => $categories['backgroundColor'],
                                ]
                            ]
                        ]
                    ]); ?>
                </div>
                <div class="col-md-6">
                    <h2><?= Yii::t('app', 'Subscriptions by category'); ?></h2>
                    <?= ChartJs::widget([
                        'type' => 'pie',
                        'options' => [
                            'height' => 90,
                        ],
                        'clientOptions' => [
                            'legend' => [
                                'position' => 'left'
                            ]
                        ],
                        'data' => [
                            'labels' => $subscriptions['labels'],
                            'datasets' => [
                                [
                                    'data' => $subscriptions['data'],
                                    'backgroundColor' => $subscriptions['backgroundColor'],
                                ]
                            ]
                        ]
                    ]); ?>
                </div>
            </div>

        </div>
    </div>
</div>
