<div class="col-md-12 col-lg-12 px-4">
    <div class="row">
        <div class="col-md-6 col-lg-4">
            <div class="mb-3">
                <label for="firstName" class="form-label">
                    <?= lang('Users.firstName') ?> *
                </label>
                <input tabindex="1" type="text" id="firstName" name="first_name" maxLength="150" class="form-control"
                       value="<?= old('first_name', $user->first_name) ?>">
            </div>
        </div>

        <div class="col-md-6 col-lg-4">
            <div class="mb-3">
                <label for="lastName" class="form-label">
                    <?= lang('Users.lastName') ?> *
                </label>
                <input tabindex="2" type="text" id="lastName" name="last_name" maxLength="150" class="form-control"
                       value="<?= old('last_name', $user->last_name) ?>">
            </div>
        </div>

        <div class="col-md-6 col-lg-4">
            <div class="mb-3">
                <label for="email" class="form-label">
                    <?= lang('Users.email') ?>*
                </label>
                <input tabindex="3" type="email" id="email" name="email" maxLength="150" class="form-control"
                       value="<?= old('email', $user->email) ?>">
            </div>
        </div>
    </div>

    <div class="row">
        <div class="mb-3">
            <div class="form-group">
                <label for="group" class="form-label"> <?= lang('Users.group') ?></label>
                <select tabindex="5" name="group[]" id="group" multiple="multiple"
                        class="form-control select2 form-select">
                    <option value=""><?= lang('Basic.global.pleaseSelectA', [lang('Users.group')]) ?></option>
                    <?php
                    $selectedGroups = isset($selectedGroups) && is_array($selectedGroups) ? $selectedGroups : [];
                    $selectedKeywords = array_map(fn($group) => $group->group, $selectedGroups);
                    foreach ($groups as $item) :
                        $isSelected = in_array($item->keyword, $selectedKeywords) ? 'selected' : '';
                        ?>
                        <option value="<?= $item->keyword ?>"
                                data-select2-id=<?= $item->keyword ?> <?= $isSelected ?>>
                            <?= $item->title ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>
        <div class="mb-3">
            <div class="form-group">
                <label for="chat_departments" class="form-label"> <?= lang('Users.chatDepartments') ?></label>
                <select tabindex="11" name="chatDepartments[]" id="chat_departments" multiple="multiple"
                        class="form-control select2 form-select">
                    <?php
                    $selectedChatDepartments = isset($chatDepartmentUser) && is_array($chatDepartmentUser) ? $chatDepartmentUser : [];
                    $selectedKeywords = array_map(fn($chatDepartment) => $chatDepartment->name, $selectedChatDepartments);
                    foreach ($chatDepartments as $item) :
                        $isSelected = in_array($item->name, $selectedKeywords) ? 'selected' : '';
                        ?>
                        <option value="<?= $item->name ?>"
                                data-select2-id=<?= $item->name ?> <?= $isSelected ?>>
                            <?= $item->display ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>
        <div class="mb-3">
            <label for="cliente_id" class="form-label">
                <?= lang('Presupuestos.clienteId') ?>
            </label>
            <select tabindex="7" id="cliente_id" name="cliente_id" class="form-control select2bs2" style="width: 100%;">

                <?php if (isset($clienteList) && is_array($clienteList) && !empty($clienteList)) :
                    foreach ($clienteList as $k => $v) : ?>
                        <option value="<?= $k ?>" <?= $k == $user->cliente_id ? ' selected' : '' ?>>
                            <?= $v ?>
                        </option>
                    <?php endforeach;
                endif; ?>
            </select>
        </div>
    </div>

    <div class="row">
        <div class="col-md-6 col-lg-6">
            <div class="mb-3">
                <label for="status" class="form-label">
                    <?= lang('Users.blocked') ?>
                </label>
                <?php $isBanned = old('blocked', $user->status); ?>
                <select tabindex="4" name="status" id="status" class="select2 form-control">
                    <option value="0" <?= is_null($isBanned) ? 'selected' : '' ?>><?= lang("Users.non_blocked") ?></option>
                    <option value="1" <?= $isBanned === "banned" ? 'selected' : '' ?>><?= lang("Users.blocked") ?></option>
                </select>
            </div>
        </div>

        <div class="col-md-6 col-lg-6">
            <div class="mb-3">
                <label for="active" class="form-label">
                    <?= lang('Users.status') ?>
                </label>
                <?php $isActive = old('status', $user->active); ?>
                <select tabindex="6" name="active" id="active" class="select2 form-control">
                    <option value="1" <?= $isActive ? 'selected' : '' ?>><?= lang("Users.global_active") ?></option>
                    <option value="0" <?= $isActive ? '' : 'selected' ?>><?= lang("Users.global_inactive") ?></option>
                </select>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-6 col-lg-6">
            <div class="mb-3">
                <label for="new_pwd" class="form-label">
                    <?= lang('Users.password') ?>
                </label>
                <input
                        tabindex="8"
                        type="text"
                        id="new_pwd"
                        name="new_pwd"
                        maxLength="50"
                        class="form-control"
                        placeholder="Introduzca contraseña para cambiarla"
                        value=""
                >
            </div>
        </div>

        <div class="col-md-6 col-lg-6">
            <div class="mb-3">
                <label for="new_pwd_confirm" class="form-label">
                    Repita <?= lang('Users.password') ?>
                </label>
                <input
                        tabindex="9"
                        type="text"
                        id="new_pwd_confirm"
                        name="new_pwd_confirm"
                        maxLength="50"
                        class="form-control"
                        placeholder="Repita la contraseña para cambiarla"
                        value=""
                >
            </div>
        </div>
    </div>

    <div class="row">
        <div class="mb-3">
            <label for="comments" class="form-label">
                Comentarios
            </label>
            <textarea
                    rows="3"
                    id="comments"
                    name="comments"
                    style="height: 10em;"
                    class="form-control"
            ><?=old('comments', $user->comments) ?></textarea>
        </div>
    </div>

</div><!--//.col -->



