/**
 * This file is part of Anis Client.
 *
 * @copyright Laboratoire d'Astrophysique de Marseille / CNRS
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';

import { Instance } from 'src/app/metamodel/models';
import { UserProfile } from 'src/app/auth/user-profile.model';

/**
 * @class
 * @classdesc Navbar component.
 */
@Component({
    selector: 'app-navbar',
    templateUrl: 'navbar.component.html',
    styleUrls: [ 'navbar.component.scss' ],
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class NavbarComponent {
    @Input() links: {label: string, icon: string, routerLink: string}[];
    @Input() isAuthenticated: boolean;
    @Input() userProfile: UserProfile = null;
    @Input() baseHref: string;
    @Input() authenticationEnabled: boolean;
    @Input() apiUrl: string;
    @Input() instance: Instance;
    @Output() login: EventEmitter<any> = new EventEmitter();
    @Output() logout: EventEmitter<any> = new EventEmitter();
    @Output() openEditProfile: EventEmitter<any> = new EventEmitter();

    /**
     * Returns logo href.
     *
     * @return  string
     */
    getLogoHref(): string {
        if (this.instance.config.design.design_logo) {
            return `${this.apiUrl}/download-instance-file/${this.instance.name}/${this.instance.config.design.design_logo}`;
        }
        return 'assets/cesam_anis40.png';
    }
}