<?php
    /**
     * @var AppView $this
     * @var Icing\Model\Entity\User $user
     * @var string[] $userGroups
     */

    use App\View\AppView;

    $this->assign('title', 'New User');

    $this->Breadcrumbs->add('Users', ['action' => 'index']);

?>

<?= $this->Form->create($user) ?>

<div class="card">
    <div class="card-header">
        <h3 class="card-title m-0">User Details</h3>
    </div>

    <div class="card-body">
        <?php
            echo $this->Form->control('name');
            if ($this->Auth->isAdmin()) {
                echo $this->Form->control('user_group_id', ['options' => $userGroups, 'empty' => true]);
            }
            echo $this->Form->control('email', ['autocomplete' => 'off']);
            $btn = $this->Html->tag(
                'button',
                '',
                [
                    'type' => 'button',
                    'class' => 'input-group-text px-4 text-secondary link-primary',
                    'data-toggle-password'
                ]
            );
            echo $this->Form->control(
                'password',
                [
                    'label'                      => 'Choose a Password',
                    'autocomplete'               => 'new-password',
                    'data-toggle-password-input' => true,
                    'append'                     => $btn,
                    'value'                      => '',
                ]
            );
            echo $this->Form->control(
                'password_confirmation',
                [
                    'label'                      => 'Password Confirmation - <span class="text-muted"> Passwords must match</span>',
                    'autocomplete'               => 'new-password',
                    'type'                       => 'password',
                    'data-toggle-password-input' => true,
                    'append'                     => $btn
                ]
            );
        ?>
    </div>
</div>

<?php
    $this->PageActions->group('bottom-right')
        ->submit('Save')
        ->group('bottom-left')
        ->link('Cancel', ['action' => 'index'], ['class' => 'btn btn-secondary']);

    echo $this->Form->end();
?>
