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_sysportlet1 } from '@widget/app/grxx3-portlet/grxx3-portlet';
import { Db_appmenu1 } from '@widget/app/grzxmenu-portlet/grzxmenu-portlet';

import { ComUtil } from '@global/util/ComUtil';
import { AppEnvironment } from 'src/environments/AppEnvironment';
import {OrgUserMobEditViewPage} from '@pages/demo/org-user-mob-edit-view/org-user-mob-edit-view.page';
import {DFMobMDViewPage} from '@pages/demo/dfmob-mdview/dfmob-mdview.page';
import {XMMobMDViewPage} from '@pages/demo/xmmob-mdview/xmmob-mdview.page';
import {WFWorkListMobMDViewPage} from '@pages/demo/wfwork-list-mob-mdview/wfwork-list-mob-mdview.page';
import {ZBMobCalendarViewPage} from '@pages/demo/zbmob-calendar-view/zbmob-calendar-view.page';
import {AppPortalView2Page} from '@pages/demo/app-portal-view2/app-portal-view2.page';


@Component({
  selector: 'ctrl-dashboard-dashboard',
  templateUrl: './app-portal-view-db-dashboard.html',
  styleUrls: ['./app-portal-view-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_sysportlet1)
     private db_sysportlet1: Db_sysportlet1;

    /**
     * 子组件
     */
     @ViewChild(Db_appmenu1)
     private db_appmenu1: Db_appmenu1;
    
    /**
     * 组件数组
     */
     private $componentsArray:Array<any> =['db_sysportlet1','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 });
                });
            });
        }
  }


}