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


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

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

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

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

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

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

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

    }

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

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




}