<?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 = 'Add User';
?>

<div class="page-title">
    <i class="fa fa-user-plus"></i> Add New 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-user-plus"></i> 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;', 'placeholder' => 'First name']) ?>
        <?= $form->field($model, 'last_name')->textInput(['class' => 'form-control', 'style' => 'padding-left:14px;', 'placeholder' => 'Last name']) ?>
        <?= $form->field($model, 'username')->textInput(['class' => 'form-control', 'style' => 'padding-left:14px;', 'placeholder' => 'Username']) ?>
        <?= $form->field($model, 'email')->textInput(['class' => 'form-control', 'style' => 'padding-left:14px;', 'placeholder' => 'Email address']) ?>

        <!-- Password (raw, not bound to model hash) -->
        <div class="form-group" style="margin-bottom:18px;">
            <label>Password <span class="text-danger">*</span></label>
            <input type="password" name="User[password_raw]" id="user-password"
                   class="form-control" style="padding-left:14px;" placeholder="Password" required>
        </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> Save User', ['class' => 'lms-btn lms-btn-success']) ?>
        </div>

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