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 { ComUtil } from '@global/util/ComUtil';
import { AppEnvironment } from 'src/environments/AppEnvironment';


@Component({
	selector: 'ctrl-default-drtab',
	templateUrl: './default-drtab.html',
	styleUrls: ['./default-drtab.scss'],
})
export class DRTab implements OnInit {

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

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


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

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

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

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

    }


    /**
     * 返回
     *
     * @memberof DRTab
     */
    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();
        }
    }

    @Output() public ctrldataschange = new EventEmitter();

	public relationship:any ="form";

	ngOnInit() {
        this.ctrldataschange.emit({type:'drtab',value:'form'});
    }

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

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

    /**
     * 数据关系分页部件选中事件
     *
     * @type {any}
     * @memberof DRTab
     */
    public segmentChanged($event:any){
        this.ctrldataschange.emit({type:'drtab',value:$event.detail.value});
    }

}