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-portal-view3-db-dashboard/app-portal-view3-db-dashboard';


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

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

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

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

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

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

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

    }

    /**
     * 返回
     *
     * @type {*}
     * @memberof AppPortalView3
     */
    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 AppPortalView3
     */
    private engineInit(): void {
    }

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




}