/**
 * 实体日历视图
 *
 * @class IBizCalendarViewController
 * @extends {IBizMDViewController}
 */
class IBizCalendarViewController extends IBizMDViewController {

    /**
     * Creates an instance of IBizCalendarViewController.
     * 创建 IBizCalendarViewController 实例
     * 
     * @param {*} [opts={}]
     * @memberof IBizCalendarViewController
     */
    constructor(opts: any = {}) {
        super(opts);
    }

    /**
     * 部件初始化
     * 
     * @memberof IBizCalendarViewController
     */
    public onInitComponents(): void {
        super.onInitComponents();

        const calender = this.getMDCtrl();
        if (calender) {
            // 双击行数据
            calender.on(IBizCalendar.ROWDBLCLICK).subscribe((args:any) => {
                this.onSelectionChange(args);
                this.onDataActivated(args[0]);
            });
            calender.on(IBizCalendar.ROWDBLCLICKNEWDATA).subscribe((args:any) => {
                this.onNewData(args[0]);
            });
        }
    }

    /**
     * 新建功能
     *
     * @param {*} [arg={}]
     * @returns {void}
     * @memberof IBizCalendarViewController
     */
    public onNewData(arg:any = {}): void {

        let loadParam = {};
        Object.assign(loadParam, arg);
        if (this.getViewParam()) {
            Object.assign(loadParam, this.getViewParam());
        }
        if (this.getParentMode()) {
            Object.assign(loadParam, this.getParentMode());
        }
        if (this.getParentData()) {
            Object.assign(loadParam, this.getParentData());
        }
        if (this.isEnableRowEdit() && (this.getMDCtrl() && this.getMDCtrl().getOpenEdit())) {
            this.doNewRow(loadParam);
            return;
        }
        if (this.isEnableBatchAdd()) {
            this.doNewDataBatch(loadParam);
            return;
        }
        if (this.doNewDataWizard(loadParam)) {
            return;
        }

        Object.assign(loadParam, { openerid: this.getId(), pviewusage: this.getViewUsage() });
        this.doNewDataNormal(loadParam);
    }

    /**
     * 获取多项数据控件对象
     * 
     * @returns {*} 
     * @memberof IBizCalendarViewController
     */
    public getMDCtrl(): any {
        return this.getCanender();
    }

    /**
     * 获取表格部件对象
     * 
     * @returns {*} 
     * @memberof IBizCalendarViewController
     */
    public getCanender(): any {
        return this.getControl('calendar');
    }
}