import { Component, OnInit,Input,Output,EventEmitter,ViewContainerRef, ViewChild} from '@angular/core';
import { Subject } from 'rxjs';
import { Http } from '@global/service/Http';
import { AppNotification } from '@global/service/Notification';
import { NavController, ModalController } from '@ionic/angular';
import { App } from '@global/service/App';
import { Db_appmenu1 } from '@widget/app/gzsqmenu-portlet/gzsqmenu-portlet';

import { ComUtil } from '@global/util/ComUtil';
import { AppEnvironment } from 'src/environments/AppEnvironment';
import {HTMobMDViewPage} from '@pages/demo/htmob-mdview/htmob-mdview.page';
import {BGYPTreeExpViewPage} from '@pages/demo/bgyptree-exp-view/bgyptree-exp-view.page';
import {AppPortalView4Page} from '@pages/demo/app-portal-view4/app-portal-view4.page';
import {AppPortalView3Page} from '@pages/demo/app-portal-view3/app-portal-view3.page';


@Component({
  selector: 'ctrl-dashboard-dashboard',
  templateUrl: './app-portal-view2-db-dashboard.html',
  styleUrls: ['./app-portal-view2-db-dashboard.scss']
})
export class Dashboard  implements OnInit{

    /**
     * 名称
     *
     * @type {string}
     * @memberof Dashboard
     */
    @Input() public name: string;

    /**
     * 视图通讯对象
     *
     * @type {Subject<ViewState>}
     * @memberof Dashboard
     */
    @Input() public viewState: Subject<ViewState>;


    /**
     * 是否为内嵌视图
     *
     * @type {boolean}
     * @memberof Dashboard
     */
    @Input() public isembeddedView: boolean;

    /**
     * 是否为模态模式
     *
     * @type {boolean}
     * @memberof Dashboard
     */
    @Input() public isModalMode: boolean;

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

    constructor(private $http: Http, private $notification: AppNotification,private $navCtrl:NavController,private $app:App,private $modalCtrl: ModalController) {

    }


    /**
     * 返回
     *
     * @memberof Dashboard
     */
    public backView() {
        if (this.isModalMode) {
            let res: any;
            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();
        }
    }

	public getDatas(): any[] {
        return [];
    }

    public getData(): any {
        return {};
    }


    /**
     * 子组件
     */
     @ViewChild(Db_appmenu1)
     private db_appmenu1: Db_appmenu1;
    
    /**
     * 组件数组
     */
     private $componentsArray:Array<any> =['db_appmenu1',];

    /**
     * angular 生命周期
     *
     * @memberof Dashboard
     */
    ngOnInit(): void {
    if (this.viewState) {
            this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                this.$componentsArray.forEach((_name: string) => {
                    this.viewState.next({ tag: _name, action: action, data: data });
                });
            });
        }
  }


}