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/clsqmenu-portlet/clsqmenu-portlet';

import { ComUtil } from '@global/util/ComUtil';
import { AppEnvironment } from 'src/environments/AppEnvironment';
import {YCSQMobEditViewPage} from '@pages/demo/ycsqmob-edit-view/ycsqmob-edit-view.page';
import {YCSQUsr2MobEditViewPage} from '@pages/demo/ycsqusr2-mob-edit-view/ycsqusr2-mob-edit-view.page';


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


}