<?php
    use common\modules\language\models\Language;
    use yii\db\ActiveRecord;
    use yii\helpers\Html;
    use yii\web\View;
    use yii\widgets\ActiveForm;
    
    /**
     * @var Language[]   $languages
     * @var string       $form_view
     * @var ActiveRecord $model_langs
     * @var ActiveForm   $form
     * @var View         $this
     * @var string       $id_prefix
     */
?>
<div>
    <?php
        if(count($languages) > 1) {
            ?>
            <ul class="nav nav-tabs text-uppercase">
                <?php
                    $first = true;
                    foreach($model_langs as $lang => $model_lang) {
                        if(!array_key_exists($lang, $languages)) {
                            continue;
                        }
                        echo Html::tag('li', Html::a($languages[ $lang ]->url, [
                            '',
                            '#' => $id_prefix . '_' . $lang,
                        ], [ 'data-toggle' => 'tab' ]), [
                            'class' => $first ? 'active' : '',
                        ]);
                        $first = false;
                    }
                ?>
            </ul>
            <div class="tab-content">
                <?php
                    $first = true;
                    foreach($model_langs as $lang => $model_lang) {
                        if(!array_key_exists($lang, $languages)) {
                            continue;
                        }
                        echo Html::tag('div', $this->render($form_view, [
                            'model_lang' => $model_lang,
                            'language'   => $languages[ $lang ],
                            'form'       => $form,
                        ]), [
                            'class' => 'tab-pane' . ( $first ? ' active' : '' ),
                            'id'    => $id_prefix . '_' . $lang,
                        ]);
                        $first = false;
                    }
                ?>
            </div>
            <?php
        } else {
            $language = current($languages);
            if(isset( $model_langs[ $language->language_id ] )) {
                echo $this->render($form_view, [
                    'model_lang' => $model_langs[ $language->language_id ],
                    'language'   => $language,
                    'form'       => $form,
                ]);
            }
        }
    ?>
</div>
