import { Component, HostListener, ViewChild } from '@angular/core';
import { FeatureFlagsService } from '@shared/services/feature-flags.service';
import { OverlayPanel } from 'primeng/overlaypanel';
import { LocalizationService } from '@shared/services';

@Component({
    selector: 'share-panel',
    templateUrl: './share-panel.component.html',
})
export class SharePanelComponent {
    @ViewChild('sharePanel')
    panel: OverlayPanel;

    link: string;

    constructor(private featuresService: FeatureFlagsService, private localizationService: LocalizationService) {}

    isChina() {
        return this.localizationService.Language === 'zh' || this.localizationService.Country === 'cn';
    }

    get isSocialShareButtonVisible() {
        return !this.isChina() && this.featuresService.NON_CHINESE_SOCIAL_SHARE_BUTTONS;
    }

    get isWeiboButtonVisible() {
        return this.isChina();
    }

    public togglePanel(event: MouseEvent, flightLink = 'https://aeroflot.ru') {
        this.link = flightLink;
        this.panel.toggle(event, event.currentTarget);
    }

    @HostListener('body:scroll')
    private onScroll() {
        this.panel.hide();
    }
}
