import { Component, OnInit,AfterViewInit,Output,Input,EventEmitter,ViewChild,ElementRef } from '@angular/core';
import { Subject,Unsubscribable } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { NavController,ModalController } from '@ionic/angular';
import { AppNotification } from '@global/service/Notification';
import { App } from '@global/service/App';
import { Http } from '@global/service/Http';
import { ComUtil } from '@global/util/ComUtil';
import { AppEnvironment } from 'src/environments/AppEnvironment';


import { Calendar } from '@widget/zb/zbxx-calendar/zbxx-calendar';

@Component({
  selector: 'view-zbmob-calendar-view',
  templateUrl: './zbmob-calendar-view.page.html',
  styleUrls: ['./zbmob-calendar-view.page.scss']
})
export class ZBMobCalendarViewPage implements OnInit,AfterViewInit {

    /**
     * 子组件Calendar
     *
     * @public
     * @type {Subject}
     * @memberof ZBMobCalendarView
     */
    @ViewChild(Calendar)
    private calendar: Calendar;

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

    /**
     * 路由传递参数
     *
     * @public
     * @type {void}
     * @memberof ZBMobCalendarView
     */
    public $route ={};

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

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

    /**
     * 是否嵌入分页导航视图
     *
     * @memberof TestEntity2MobPickupView
     */
    @Input() isTabexp:boolean =false;

    /**
     * 视图值变化事件
     *
     * @public
     * @type {EventEmitter}
     * @memberof ZBMobCalendarView
     */    
    @Output() public viewdataschange =new EventEmitter();

    /**
     * 视图参数
     *
     * @public
     * @type {Subject}
     * @memberof ZBMobCalendarView
     */
    @Input() public viewdata:any;

    /**
     * 父数据对象
     *
     * @protected
     * @type {*}
     * @memberof ZBMobCalendarView
     */
    protected srfparentdata: any = {};

    /**
     * 是否为内敛视图
     *
     * @public
     * @type {EventEmitter}
     * @memberof ZBMobCalendarView
     */ 
    @Input() public isembeddedView:boolean =false;

    /**
     * 视图值加载完成事件
     *
     * @public
     * @type {EventEmitter}
     * @memberof ZBMobCalendarView
     */ 
    @Output() public viewload =new EventEmitter();

    /**
     * 视图的关联试图Map
     *
     * @public
     * @type {Map}
     * @memberof ZBMobCalendarView
     */
    public RefViewMap =new Map();


    /**
     * 引擎初始化
     *
     * @private
     * @memberof ZBMobCalendarView
     */
    private engineInit(): void {
    }


     /**
     * angular生命周期(在ngOnInit之后)
     *
     * @memberof ZBMobCalendarView
     */
    public ngAfterViewInit(){
        this.engineInit();
        this.viewState.next({ tag:'calendar', action: 'load', data: this.viewdata });

        this.registerRefView();
    }




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

    /**
     * 嵌入视图点击更多
     *
     * @public
     * @memberof ZBMobCalendarView
     */
    public async click_more(){
        let leftopts:Array<any> =[
    ];
        let rightopts:Array<any> =[
    ];
        let opts:Array<any>=leftopts.concat(rightopts);
        const result: string = await this.$app.openActionSheet({items:opts});
        let _this =this;
    }

    /**
     * 点击toolbar的操作组事件
     *
     * @public
     * @memberof ZBMobCalendarView
     */
    public  async openActionSheet(data:any){

        
    }

    /**
     * 注册关联视图
     *
     * @public
     * @memberof ZBMobCalendarView
     */    
    public registerRefView(){
    }   

    
    /**
     * 实例化对象
     *
     * @memberof ZBMobCalendarView
     */
    constructor(public $http:Http,public $navCtrl: NavController, public $notification: AppNotification, public $activatedRoute: ActivatedRoute,public $modalCtrl:ModalController,public $app:App) {
        this.$activatedRoute.queryParams.subscribe(params => {
        this.$route ="";
        if(params){
            this.$route =JSON.stringify(params);
        }
        })
    }

    /**
     * angular生命周期(组件初始化)
     *
     * @memberof ZBMobCalendarView
     */
    public ngOnInit() {
       
    }

    /**
     * 视图抛出值变化事件
     *
     * @public
     * @memberof ZBMobCalendarView
     */
    public viewDataChanges($event:any){
        this.viewdataschange.emit($event);
    }
}


