<?php

use backend\models\AdminMenu;
use common\models\Tools;
use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model backend\models\AdminMenu */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="admin-menu-form">

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

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

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

    <?= $form->field($model, 'hide_min')->checkbox() ?>

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

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

    <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
        <div class="panel panel-default">
            <div class="panel-heading" role="tab" id="headingOne">
                <h4 class="panel-title">
                    <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                        <?= Yii::t('app', 'Parent menu item') ?>
                    </a>
                </h4>
            </div>
            <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
                <ul class="list-group checkboxer">
                    <?php
                    $roots = AdminMenu::buildMenuSelect();
                    echo $form->field($model, 'admin_menu_pid', ['options' => ['class' => 'form-group list-group-item level0 checkboxer_container', 'tag' => 'li']])->error(false)->radio(['value' => 0, 'uncheck' => null, 'label' => Yii::t('app', 'root'), 'labelOptions' => ['class' => 'checkboxer_label']]);
                    foreach($roots as $root) {
                        echo $form->field($model, 'admin_menu_pid', ['options' => ['class' => 'form-group list-group-item level1 checkboxer_container', 'tag' => 'li']])->error(false)->radio(['value' => $root['id'], 'uncheck' => null, 'label' => Yii::t('app', $root['label']), 'labelOptions' => ['class' => 'checkboxer_label']]);
                        if($root['items']) {
                            foreach($root['items'] as $submenu) {
                                echo $form->field($model, 'admin_menu_pid', ['options' => ['class' => 'form-group list-group-item level2 checkboxer_container', 'tag' => 'li']])->error(false)->radio(['value' => $submenu['id'], 'uncheck' => null, 'label' => Yii::t('app', $submenu['label']), 'labelOptions' => ['class' => 'checkboxer_label']]);
                            }
                        }
                    }
                    ?>
                </ul>
            </div>
        </div>
    </div>

    <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') . ' btn-flat']) ?>
    </div>

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

</div>
