import { Component, Input, Output, EventEmitter, ViewChild, AfterViewInit } from '@angular/core';
import { AppEnvironment } from 'src/environments/AppEnvironment';

@Component({
    selector: 'app-rotation-chart',
    templateUrl: 'app-rotation-chart.html',
    styleUrls: ['app-rotation-chart.scss']
})
export class AppRotationChart implements AfterViewInit {
    @ViewChild('IonSlides')
    ionSlides;
    /**
     * 
     *
     * @type {any[]}
     * @memberof AppRotationChart
     */
    @Input()
    set items(val: any[]) {
        if (val && val instanceof Array) {
            if (!Object.is(JSON.stringify(this.$items), JSON.stringify(val))) {
                if(val.length >0){
                    val.forEach((item:any) =>{
                        if(item && item.image){
                            item.image = JSON.parse(item.image);
                        }
                    });
                }
                this.$items = val;
                if (this.ionSlides) {
                    this.ionSlides.update();
                    this.ionSlides.startAutoplay();
                }
            }
        }
    }
    @Input()
    height: string = '130pt';
    /**
     * 点击
     *
     * @type {EventEmitter<any>}
     * @memberof AppRotationChart
     */
    @Output()
    itemClick: EventEmitter<any> = new EventEmitter();
    /**
     *
     *
     * @type {any[]}
     * @memberof AppRotationChart
     */
    public $items: any[] = [];

    /**
     * 平台图片获取路径
     *
     * @type {string}
     * @memberof AppRotationChart
     */
    public url: string;

    /**
     * Creates an instance of AppRotationChart.
     * @memberof AppRotationChart
     */
    constructor() {
        this.url = AppEnvironment.BaseUrl + AppEnvironment.ExportFile + '/';
    }

    @Input() public title:string;

    
    /**
     * 视图初始化完毕
     *
     * @memberof AppRotationChart
     */
    public ngAfterViewInit(): void {
        this.ionSlides.startAutoplay();
    }

    /**
     * 点击
     *
     * @param {*} item
     * @memberof AppRotationChart
     */
    public onClick(item: any): void {
        this.itemClick.emit(item);
    }

}