{include file="$template/includes/flashmessage.tpl"}
{assign var="permissionsCount" value=0}
{assign var="enabledPermissionsCount" value=0}
{foreach $permissions as $permission}
    {assign var="permissionsCount" value=$permissionsCount+1}
    {if $userPermissions->hasPermission($permission.key)}
        {assign var="enabledPermissionsCount" value=$enabledPermissionsCount+1}
    {/if}
{/foreach}

<section class="dashboard-page-section">
    <section class="dashboard-analytics-grid dashboard-analytics-grid--three">
        <article class="dashboard-analytics-card dashboard-analytics-card--green dashboard-analytics-card--spark">
            <span class="dashboard-analytics-card__icon"><i class="fas fa-user-lock"></i></span>
            <div class="dashboard-analytics-card__copy">
                <span class="dashboard-analytics-card__label">{lang key='userManagement.managePermissions'}</span>
                <strong class="dashboard-analytics-card__value">{$enabledPermissionsCount}</strong>
                <span class="dashboard-analytics-card__meta">{lang key='userManagement.permissions'}</span>
            </div>
            <span class="dashboard-analytics-card__line dashboard-analytics-card__line--green"></span>
        </article>
        <article class="dashboard-analytics-card dashboard-analytics-card--mint dashboard-analytics-card--spark">
            <span class="dashboard-analytics-card__icon"><i class="fas fa-tasks"></i></span>
            <div class="dashboard-analytics-card__copy">
                <span class="dashboard-analytics-card__label">{lang key='userManagement.permissions'}</span>
                <strong class="dashboard-analytics-card__value">{$permissionsCount}</strong>
                <span class="dashboard-analytics-card__meta">{lang key='userManagement.allPermissions'}</span>
            </div>
            <span class="dashboard-analytics-card__line dashboard-analytics-card__line--mint"></span>
        </article>
        <article class="dashboard-analytics-card dashboard-analytics-card--amber dashboard-analytics-card--spark">
            <span class="dashboard-analytics-card__icon"><i class="fas fa-envelope"></i></span>
            <div class="dashboard-analytics-card__copy">
                <span class="dashboard-analytics-card__label">{lang key='userManagement.emailAddress'}</span>
                <strong class="dashboard-analytics-card__value">{$user->email}</strong>
                <span class="dashboard-analytics-card__meta">{lang key='userManagement.userDescriptor'}</span>
            </div>
            <span class="dashboard-analytics-card__line dashboard-analytics-card__line--amber"></span>
        </article>
    </section>

    <section class="dashboard-panel dashboard-page-table-panel">
        <div class="dashboard-page-heading dashboard-page-heading--inline">
            <div class="dashboard-page-heading__title">
                <span class="dashboard-page-heading__icon"><i class="fas fa-user-lock"></i></span>
                <div>
                    <h1 class="dashboard-page-title">{lang key='userManagement.managePermissions'}</h1>
                    <p class="dashboard-panel__copy">{$user->email}</p>
                    <div class="dashboard-page-heading__actions">
                        <a href="{routePath('account-users')}" class="dashboard-link dashboard-link--hero">
                            <i class="fas fa-arrow-left"></i>
                            {lang key='navUserManagement'}
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <div class="dashboard-panel">
            <div class="dashboard-panel__header">
                <div>
                    <h2 class="dashboard-panel__title">{lang key='userManagement.permissions'}</h2>
                    <p class="dashboard-panel__copy">{lang key='userManagement.choosePermissions'}</p>
                </div>
            </div>

            <form method="post" action="{routePath('account-users-permissions-save', $user->id)}">
                {foreach $permissions as $permission}
                    <label class="form-check d-block mb-3">
                        <input type="checkbox" class="form-check-input mr-2" name="perms[{$permission.key}]" value="1"{if $userPermissions->hasPermission($permission.key)} checked{/if}>
                        <span>{$permission.title}</span>
                        <br>
                        <span class="text-muted">{$permission.description}</span>
                    </label>
                {/foreach}

                <div class="form-group mt-4">
                    <button type="submit" class="btn btn-primary">
                        {lang key="clientareasavechanges"}
                    </button>
                    <a href="{routePath('account-users')}" class="btn btn-default">
                        {lang key="clientareacancel"}
                    </a>
                </div>
            </form>
        </div>
    </section>
</section>
