<%#
 Copyright 2013-2019 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
import { Component, OnInit } from '@angular/core';
<%_ if (authenticationType !== 'oauth2') { _%>
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { JhiEventManager } from '<%= styleLibrary === 'bootstrap' ? 'ng-jhipster' : 'ng-fedhipster' %>';
<%_ } _%>

import { <% if (authenticationType !== 'oauth2') { %>LoginModalService<% } else { %>LoginService<% } %>, AccountService, Account } from 'app/core';

@Component({
    selector: '<%= jhiPrefixDashed %>-home',
    templateUrl: './home.component.html',
    styleUrls: [
        'home.scss'
    ]

})
export class HomeComponent implements OnInit {
    <%_ if (styleLibrary === 'uswds' || styleLibrary === 'octo') { _%>
    blob = {
        callOut :"Hero Callout",
        blobStatement: "Bring attention to a project priority",
        blobPara : "Support the callout with some short explanatory text. You don’t need more than a couple of sentences."
    }
    blobBtn = "Call to action";
    <%_ } _%>
    account: Account;
    <%_ if (authenticationType !== 'oauth2') { _%>
    modalRef: NgbModalRef;
    <%_ } _%>

    constructor(
        private accountService: AccountService,
        <%_ if (authenticationType !== 'oauth2') { _%>
        private loginModalService: LoginModalService,
        private eventManager: JhiEventManager
        <%_ } else { _%>
        private loginService: LoginService
        <%_ } _%>
    ) {
    }

    ngOnInit() {
        this.accountService.identity().then((account: Account) => {
            this.account = account;
        });
        <%_ if (authenticationType !== 'oauth2') { _%>
        this.registerAuthenticationSuccess();
    }

    registerAuthenticationSuccess() {
        this.eventManager.subscribe('authenticationSuccess', (message) => {
            this.accountService.identity().then((account) => {
                this.account = account;
            });
        });
        <%_ } _%>
    }

    isAuthenticated() {
        return this.accountService.isAuthenticated();
    }

    login() {
        <%_ if (authenticationType !== 'oauth2') { _%>
        this.modalRef = this.loginModalService.open();
        <%_ } else { _%>
        this.loginService.login();
        <%_ }_%>
    }
}
