<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use alexantr\ckeditor\CKEditor;

?>

<div class="email-templates-form">

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

    <?= $form->field($model, 'template_name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'dedicated_for')->textInput(['readonly' => true, 'value' => Yii::t('app', $model->dedicated_for)]) ?>

    <?= $form->field($model, 'is_active')->dropDownList([
            0 => Yii::t('app', 'No'),
            1 => Yii::t('app', 'Yes'),
        ], ['class' => 'form-control']) ?>

    <?php if(Yii::$app->session->hasFlash('missing_variables')): ?>
        <div class="alert alert-danger">
            <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
            <?= Yii::$app->session->getFlash('missing_variables') ?>
        </div>
    <?php endif; ?>

    <?php if($template_variables): ?>
        <div class='alert alert-info'>
            <b><?= Yii::t('app', 'Attention') . ': ' ?></b>
            <?= Yii::t('app', 'The following variables must be used in the template') ?>
            <br>
            <ul>
                <?php foreach($template_variables as $variable): ?>
                    <li>
                        <b><?= Yii::t('app', $variable->variable->var_name) . ': ' ?></b>
                        <?= $variable->variable->var_code ?>
                    </li>
                <?php endforeach; ?>
            </ul>
        </div>
    <?php endif; ?>

    <?= $form->field($model, 'content')->widget(CKEditor::className(), [
        'clientOptions' => [
            'language' => Yii::$app->language,
            'removePlugins' => 'image'
        ]
    ]) ?>

    <div class="form-group">
        <?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-success']) ?>
    </div>

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

</div>
