import { Component } from '@angular/core';
import { Input } from '@angular/core';
import { ImageSource } from '@nativescript/core';
import { ImageService } from './../../../services/image.service';

@Component({
    selector: 'EduEventLogo',
    moduleId: module.id,
    templateUrl: './edu-event-logo.component.html',
    styleUrls: ['./_edu-event-logo.component.scss']
})
export class EduEventLogoComponent {
    private _logoId: number;
    @Input()
    set logoId(id) {
        if (id !== this._logoId) {
            this._logoId = id;
            this.loadLogo()
        }
    };
    get logoId() {
        return this._logoId;
    }
    @Input()
    height: number = 50;
    logo: ImageSource;
    logoLoading: boolean;
    constructor(
        private logoService: ImageService,
    ) {
    }

    loadLogo() {
        this.logo = null;
        if (!this.logoId) {
            this.logoLoading = false;
            return;
        }

        this.logoLoading = true;
        this.logoService.loadEduEventLogo(this.logoId).then(i => {
            this.logo = i;
            this.logoLoading = false
        })
    }
}
