import { Component,ViewChild, AfterViewInit,Input } from '@angular/core';
import { Subject } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { NavController,ModalController } from '@ionic/angular';
import { App } from '@global/service/App';
import { ComUtil } from '@global/util/ComUtil';
import { AppNotification } from '@global/service/Notification';
import { AppEnvironment } from 'src/environments/AppEnvironment';

import { Dashboard } from '@widget/app/app-dashboard-view-db-dashboard/app-dashboard-view-db-dashboard';


@Component({
  selector: 'view-app-dashboard-view',
  templateUrl: './app-dashboard-view.page.html',
  styleUrls: ['./app-dashboard-view.page.scss']
})
export class AppDashboardViewPage implements AfterViewInit {

    /**
     * 子组件AppDashboardView
     *
     * @type {*}
     * @memberof AppDashboardView
     */
    @ViewChild(Dashboard)
    private dashboard: Dashboard;

    /**
     * 视图状态订阅对象
     *
     * @type {*}
     * @memberof AppDashboardView
     */
    public viewState: Subject<ViewState> = new Subject();

    /**
     * 当前视图激活数据
     *
     * @public
     * @type {void}
     * @memberof AppDashboardView
     */
    public $activeData:Array<any> =[];

    /**
     * 是否为模态框弹出
     *
     * @memberof AppDashboardView
     */
    @Input() isModalMode:boolean =false;

    /**
     * 容器模型
     *
     * @type {*}
     * @memberof AppDashboardView
     */
    public containerModel: any = {
        view_dashboard: { name: 'dashboard', type: 'DASHBOARD' },
    };

    /**
     * 实例化对象
     *
     * @type {*}
     * @memberof AppDashboardView
     */
    constructor(private $navCtrl:NavController,public $modalCtrl:ModalController,public $app:App){

    }

    /**
     * 返回
     *
     * @type {*}
     * @memberof AppDashboardView
     */
    public backView(){
        let res:any;
        if(this.isModalMode){
            if(this.$activeData && this.$activeData.length >0){
                res = { ret: 'OK', result:this.$activeData };
            }else{
                res = { ret: 'NO', result:[] };
            }
            this.$modalCtrl.dismiss(res, 'close');
        }else{
            this.$navCtrl.back();
            if(this.$activeData && this.$activeData.length >0){
                res = { ret: 'OK', result:this.$activeData };
            }else{
                res = { ret: 'NO', result:[] };
            }
            this.$app.closeCallback(res);
        }
    }


    /**
     * 引擎初始化
     *
     * @private
     * @memberof AppDashboardView
     */
    private engineInit(): void {
    }

    /**
     * angular声明周期(组件初始化完毕)
     *
     * @memberof AppDashboardView
     */
    public  ngAfterViewInit() {
        this.engineInit();
        this.viewState.next({ tag: 'dashboard', action: 'load', data: {} });
    }




}