import { AfterViewInit, Component, ViewChild } from '@angular/core';
import { TelerikReportViewerComponent } from '@progress/telerik-angular-report-viewer';
import { StringResources } from './stringResources';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})

export class AppComponent implements AfterViewInit {
    @ViewChild('viewer1', { static: false }) viewer: TelerikReportViewerComponent;

    ngAfterViewInit(): void {
        // Localization demo.
        const language = navigator.language;
        let resources = StringResources.english; // Default.

        if (language === 'ja-JP') {
            resources = StringResources.japanese;
        }

        this.viewer.viewerObject.stringResources = Object.assign(this.viewer.viewerObject.stringResources, resources);

        // Set for Report Class Library definition
        //this.viewer.setReportSource({
        //    report: 'ReportLibrary.SampleReport, ReportLibrary, Version=14.2.20.1021, Culture=neutral, PublicKeyToken=null'
        //});

        //// Set for .trdp definition
        //this.viewer.setReportSource({
        //    report: 'Dashboard.trdp'
        //})

        //// Set for Core Library definition
        this.viewer.setReportSource({
            report: 'ReportLibraryCore.SampleReport, ReportLibraryCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
        })
    }

    title = "Report Viewer";
    viewerContainerStyle = {
        position: 'absolute',
        left: '5px',
        right: '5px',
        top: '40px',
        bottom: '5px',
        overflow: 'hidden',
        clear: 'both',
        ['font-family']: 'ms sans serif'
    };

    ready() { console.log('ready'); }
    viewerToolTipOpening(e: any, args: any) { console.log('viewerToolTipOpening ' + args.toolTip.text); }
}
