<?php
    /**
     * @var array   $services
     * @var integer $service_id
     * @var integer $lastId
     * @var \common\models\Price[] $prices;
     */
    
    use artbox\core\admin\assets\Select2;
    use artbox\core\admin\assets\Switchery;
    use yii\helpers\Html;
    use yii\web\View;
    use yii\widgets\ActiveForm;
    use yiister\gentelella\widgets\Panel;
    Switchery::register($this);
    $js = <<< JS
$('.switchery').each(function(idx, elem) {
  new Switchery(elem, {
    color:'#46b749',
    secondaryColor:'#e2e2e2'
  });
});

$(".select_service").select2();
JS;
    
    
    $this->registerJs($js, View::POS_READY);
?>
<div class='adm-index'>
    <?php
        $panel = Panel::begin(
            [
                'header'  => $this->title,
                'options' => [
                    'class' => 'x_panel feedback-update',
                ],
            ]
        );
    ?>
  <div class='form-admin-sort-wr'>
    <div class='form-admin-sort'>
        <?php ActiveForm::begin(
            [
                'method' => 'GET',
                'action' => [ 'price/index' ],
            ]
        ) ?>
      <div class='form-group'>
          <?php echo Html::label('Услуга');
              echo Html::dropDownList(
                  'service_id',
                  $service_id,
                  $services,
                  [
                      'prompt' => \Yii::t('core', '- All -'),
                      'id'     => 'service_id',
                      'class'  => 'form-control',
                  ]
              );
          ?>
      </div>
      <div class='form-search-btn-wr'>
          <?php echo Html::submitButton(
              'Select',
              [
                  'class' => 'btn btn-success',
              ]
          );
          ?>
      </div>
        <?php ActiveForm::end(); ?>
    </div>
  </div>
    <?php
        Select2::register($this);
        
        $js = <<<JS
            $('#service_id').select2();
JS;
        $this->registerJs($js, View::POS_READY);
        $panel::end();
    ?>
</div>

<?php
    $panel = Panel::begin(
        [
            'header'  => $this->title,
            'options' => [
                'class' => 'x_panel feedback-update',
            ],
        ]
    );
   $form = ActiveForm::begin(
    [
        'method' => 'POST',
        'action' => [ 'price/index', 'service_id' => $service_id ],
    ]
) ?>
<?php if (!empty($prices)){
  foreach ($prices as $price){?>
<div class="form-group-33-wr">
  <div class="form-group-33">
      <?php echo $form->field($price, '['.$price->id.']service_id')->hiddenInput()->label(false)?>
      <?php echo $form->field($price, '['.$price->id.']price')?>
      <?php
          foreach ($price->languages as $key => $value){
              echo $form->field($value, '['.$price->id.']['.$value->language_id.']title')->label('Название '.$value->language->url);
          }
      ?>
    
      <?= $form->field($price, '['.$price->id.']status')
               ->checkbox(
                   [
                       'class' => 'switchery',
                   ]
               ) ?>
    <a class="delete-variant delete-url remove-img-2 btn-danger btn" href="#"></a>
  </div>
  
</div>
<?php }
  }?>
<div class="form-group-33-wr">
  <div class="form-group-33" style="height: 292px">
    <a href="#" data-last="<?=(!empty($lastId) ?  $lastId : 0)?>" data-service="<?=$service_id?>" id="add-price" class="add-url-pluse btn btn-success add-gallery-btn-new"><i class="fa fa-plus"></i></a>
  </div>
</div>
<div class="style buttons-page-wr">
    <?= Html::submitButton(
        'Save', ['class' => 'btn btn-success',]
    ) ?>
</div>

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