import { Vue } from 'vue-property-decorator';
import { Subject } from 'rxjs';
import { AppServiceBase } from '@ibizstudio/runtime';
import { AppTopDrawer } from './app-top-drawer';
/**
 * 模态
 *
 * @export
 * @class AppTopDrawerContainer
 */
export class AppTopDrawerContainer {
    /**
     * Creates an instance of AppTopDrawerContainer.
     * @memberof AppTopDrawerContainer
     */
    constructor() {
        this.modalContainer = document.createElement('div');
        document.body.appendChild(this.modalContainer);
    }
    /**
     * 初始化基础数据
     *
     * @memberof AppTopDrawerContainer
     */
    initBasicData() {
        const appService = AppServiceBase.getInstance();
        this.store = appService.getAppStore();
        this.i18n = appService.getI18n();
        this.router = appService.getRouter();
    }
    /**
     * 初始化
     *
     * @protected
     * @memberof AppTopDrawerContainer
     */
    init() {
        this.vueInstance = new Vue({
            store: this.store,
            router: this.router,
            i18n: this.i18n,
            render: (h) => h(AppTopDrawer, { ref: 'AppTopDrawer' }),
        }).$mount(this.modalContainer);
    }
    /**
     * 顶部抽屉模式打开视图
     *
     * @param {{ viewname: string, title: string, width?: number, height?: number }} view 视图
     * @param {*} [viewParam={}] 视图参数
     * @param {any[]} deResParameters 关系实体参数对象
     * @param {any[]} parameters 当前应用视图参数对象
     * @param {any[]} args 多项数据
     * @param {*} [data={}] 行为参数
     * @returns {Observable<any>}
     * @memberof AppTopDrawerContainer
     */
    openDrawer(view, dynamicProps = {}, staticProps = {}) {
        view.viewname = 'app-view-shell';
        const subject = new Subject();
        this.initBasicData();
        this.getVueInstance()
            .$refs.AppTopDrawer.openModal(Object.assign(Object.assign({}, view), { dynamicProps: dynamicProps, staticProps: staticProps }))
            .then((data) => {
            subject.next(data);
            subject.complete();
            subject.unsubscribe();
        });
        return subject.asObservable();
    }
    /**
     * 获取Vue容器实例
     *
     * @protected
     * @returns {*}
     * @memberof AppTopDrawerContainer
     */
    getVueInstance() {
        if (!this.vueInstance) {
            this.init();
        }
        return this.vueInstance;
    }
}
/**
 * 唯一实例
 *
 * @protected
 * @static
 * @type {AppTopDrawerContainer}
 * @memberof AppTopDrawerContainer
 */
AppTopDrawerContainer.instance = new AppTopDrawerContainer();
// 模态服务控制器实例
export const appTopDrawerContainer = new AppTopDrawerContainer();
