<ion-header>
    <ion-toolbar>
        <ion-buttons slot="start">
            <ion-back-button [text]="'core.back' | translate"></ion-back-button>
        </ion-buttons>

        <ion-title>
            <h1>{{ 'core.login.login' | translate }}</h1>
        </ion-title>

        <ion-buttons slot="end">
            <ion-button fill="clear" (click)="openSettings()" [attr.aria-label]="'core.settings.appsettings' | translate">
                <ion-icon slot="icon-only" name="fas-gear" aria-hidden="true"></ion-icon>
            </ion-button>
            <ion-button fill="clear" (click)="showHelp()" [attr.aria-label]="'core.help' | translate">
                <ion-icon slot="icon-only" name="far-circle-question" aria-hidden="true"></ion-icon>
            </ion-button>
        </ion-buttons>
    </ion-toolbar>
</ion-header>
<ion-content class="ion-padding limited-width">
    <core-loading [hideUntil]="pageLoaded">
        <div class="ion-text-wrap ion-text-center ion-margin-bottom">
            <div class="core-login-site-logo">
                <!-- Show site logo or a default image. -->
                <img *ngIf="logoUrl" [src]="logoUrl" role="presentation" alt="" onError="this.src='assets/img/login_logo.png'">
                <img *ngIf="!logoUrl" src="assets/img/login_logo.png" role="presentation" alt="">
            </div>

            <h2 *ngIf="siteName" class="ion-padding core-sitename">
                <core-format-text [text]="siteName" [filter]="false"></core-format-text>
            </h2>
            <p class="core-siteurl">{{siteUrl}}</p>
        </div>

        <core-login-exceeded-attempts *ngIf="exceededAttemptsHTML && supportConfig && loginAttempts >= 3" [supportConfig]="supportConfig"
            [supportSubject]="'core.login.exceededloginattemptssupportsubject' | translate">
            <div [innerHTML]="exceededAttemptsHTML" (click)="exceededAttemptsClicked($event)"></div>
        </core-login-exceeded-attempts>

        <form [formGroup]="credForm" (ngSubmit)="login($event)" class="core-login-form" #credentialsForm>
            <ion-item *ngIf="siteChecked && !isBrowserSSO">
                <ion-label class="sr-only">{{ 'core.login.username' | translate }}</ion-label>
                <ion-input type="text" name="username" placeholder="{{ 'core.login.username' | translate }}" formControlName="username"
                    autocapitalize="none" autocorrect="off" autocomplete="username" enterkeyhint="next" required="true">
                </ion-input>
            </ion-item>
            <ion-item *ngIf="siteChecked && !isBrowserSSO" class="ion-margin-bottom">
                <ion-label class="sr-only">{{ 'core.login.password' | translate }}</ion-label>
                <core-show-password name="password">
                    <ion-input name="password" type="password" placeholder="{{ 'core.login.password' | translate }}"
                        formControlName="password" [clearOnEdit]="false" autocomplete="current-password" enterkeyhint="go" required="true">
                    </ion-input>
                </core-show-password>
            </ion-item>
            <ion-button expand="block" type="submit" [disabled]="siteChecked && !isBrowserSSO && !credForm.valid"
                class="ion-margin core-login-login-button ion-text-wrap">
                {{ 'core.login.loginbutton' | translate }}
            </ion-button>
            <!-- Remove this once Ionic fixes this bug: https://github.com/ionic-team/ionic-framework/issues/19368 -->
            <input type="submit" class="core-submit-hidden-enter" />

            <ng-container *ngIf="showScanQR">
                <div class="ion-text-center ion-padding core-login-site-qrcode-separator">{{ 'core.login.or' | translate }}</div>
                <ion-button expand="block" fill="outline" class="ion-margin core-login-site-qrcode" (click)="showInstructionsAndScanQR()">
                    <ion-icon slot="start" name="fas-qrcode" aria-hidden="true"></ion-icon>
                    {{ 'core.scanqr' | translate }}
                </ion-button>
            </ng-container>
        </form>

        <!-- Forgotten password option. -->
        <ion-button *ngIf="showForgottenPassword" expand="block" fill="clear"
            class="core-login-forgotten-password core-button-as-link ion-text-wrap" (click)="forgottenPassword()">
            {{ 'core.login.forgotten' | translate }}
        </ion-button>

        <ion-list *ngIf="identityProviders && identityProviders.length" class="ion-padding-top core-login-identity-providers">
            <ion-item class="ion-text-wrap">
                <ion-label>
                    <h2 class="item-heading">{{ 'core.login.potentialidps' | translate }}</h2>
                </ion-label>
            </ion-item>
            <ion-button fill="outline" *ngFor="let provider of identityProviders" class="ion-text-wrap ion-margin core-oauth-provider"
                (click)="oauthClicked(provider)" [attr.aria-label]="provider.name" expand="block">
                <img *ngIf="provider.iconurl" [src]="provider.iconurl" alt="" width="32" height="32" slot="start" aria-hidden="true">
                <ion-label>{{provider.name}}</ion-label>
            </ion-button>
        </ion-list>

        <ion-list *ngIf="canSignup || authInstructions" class="ion-padding-top core-login-sign-up">
            <ion-item class="ion-text-wrap">
                <ion-label>
                    <h2 class="item-heading">{{ 'core.login.firsttime' | translate }}</h2>
                </ion-label>
            </ion-item>
            <ion-item class="ion-text-wrap" *ngIf="authInstructions">
                <ion-label>
                    <p>
                        <core-format-text [text]="authInstructions" [filter]="false"></core-format-text>
                    </p>
                </ion-label>
            </ion-item>
            <ion-button *ngIf="canSignup" expand="block" class="ion-margin ion-text-wrap" fill="outline" (click)="openEmailSignup()">
                {{ 'core.login.startsignup' | translate }}
            </ion-button>
        </ion-list>
    </core-loading>
</ion-content>
