<vdr-action-bar>
    <vdr-ab-left></vdr-ab-left>
    <vdr-ab-right>
        <button
            class="btn btn-primary"
            *ngIf="(isNew$ | async); else: updateButton"
            (click)="create()"
            [disabled]="detailForm.invalid || detailForm.pristine"
        >
            {{ 'common.create' | translate }}
        </button>
        <ng-template #updateButton>
            <button
                class="btn btn-primary"
                (click)="save()"
                [disabled]="(detailForm.invalid || detailForm.pristine) && !permissionsChanged"
            >
                {{ 'common.update' | translate }}
            </button>
        </ng-template>
    </vdr-ab-right>
</vdr-action-bar>

<form class="form" [formGroup]="detailForm">
    <section class="form-block">
        <label>{{ 'settings.role' | translate }}</label>
        <vdr-form-field [label]="'common.description' | translate" for="description">
            <input
                id="description"
                type="text"
                formControlName="description"
                (input)="updateCode($event.target.value)"
            />
        </vdr-form-field>
        <vdr-form-field [label]="'common.code' | translate" for="code" [readOnlyToggle]="true">
            <input id="code" type="text" formControlName="code" />
        </vdr-form-field>
    </section>
    <section class="form-block">
        <label>{{ 'settings.permissions' | translate }}</label>
        <vdr-permission-grid
            [permissions]="permissions"
            (permissionChange)="setPermission($event)"
        ></vdr-permission-grid>
    </section>
</form>
