<?php
/** @var yii\web\View $this */
/** @var app\models\User $model */
/** @var app\models\MasUserGroup[] $groups */

use yii\helpers\Html;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use yii\widgets\ActiveForm;

$this->title = 'Edit User';
?>

<div class="page-title">
    <i class="fa fa-edit"></i> Edit User
    <a href="<?= Url::to(['users/index']) ?>" class="lms-btn lms-btn-primary lms-btn-sm">
        <i class="fa fa-arrow-left"></i> Back
    </a>
</div>

<div class="lms-card" style="max-width:620px;">
    <div class="lms-card-header"><i class="fa fa-edit"></i> Update User Details</div>
    <div class="lms-card-body">

    <?php $form = ActiveForm::begin([
        'options'     => ['autocomplete' => 'off'],
        'fieldConfig' => ['errorOptions' => ['class' => 'field-error']],
    ]); ?>

        <?= $form->field($model, 'first_name')->textInput(['class' => 'form-control', 'style' => 'padding-left:14px;']) ?>
        <?= $form->field($model, 'last_name')->textInput(['class' => 'form-control', 'style' => 'padding-left:14px;']) ?>
        <?= $form->field($model, 'username')->textInput(['class' => 'form-control', 'style' => 'padding-left:14px;']) ?>
        <?= $form->field($model, 'email')->textInput(['class' => 'form-control', 'style' => 'padding-left:14px;']) ?>

        <!-- New password (optional) -->
        <div class="form-group" style="margin-bottom:18px;">
            <label>New Password <small style="color:#aaa;">(leave blank to keep current)</small></label>
            <input type="password" name="User[password_raw]"
                   class="form-control" style="padding-left:14px;" placeholder="Enter new password">
        </div>

        <?= $form->field($model, 'level')->dropDownList(
            [\app\models\User::LEVEL_ADMIN => 'Administrator', \app\models\User::LEVEL_STAFF => 'Staff'],
            ['class' => 'form-control', 'style' => 'padding-left:14px;']
        ) ?>

        <?= $form->field($model, 'user_group_id')->dropDownList(
            ArrayHelper::map($groups, 'id', 'group_name'),
            ['class' => 'form-control', 'style' => 'padding-left:14px;', 'prompt' => '— Select Group —']
        ) ?>

        <?= $form->field($model, 'is_active')->dropDownList(
            ['Y' => 'Active', 'N' => 'Inactive'],
            ['class' => 'form-control', 'style' => 'padding-left:14px;']
        ) ?>

        <div style="margin-top:10px;">
            <?= Html::submitButton('<i class="fa fa-save"></i> Update User', ['class' => 'lms-btn lms-btn-success']) ?>
        </div>

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