/**
 * 在线协议渲染
 * @author xiu.wang
 */
import Vue from 'vue'
import dataSource from 'mars-pro/src/pro/mixins/dataSource'
import {post, get, postForm,download} from 'mars-pro/src/pro/request'
import {ProConfigProvideMixin} from 'mars-pro/packages/pro-config-provide';
import createVueOption from './vjson/createVueOption'
export default {
    name: 'ProOnlineRender',
    componentName: 'ProOnlineRender',
    inheritAttrs: false,
    created() { 
        this.vcomponent = createVueOption(this.vjson)(Vue, this.vjson, dataSource, ProConfigProvideMixin, this.createElementProxy, post, get, postForm,download)
    },
    watch: {
        vjson() { 
            this.vcomponent = createVueOption(this.vjson)(Vue, this.vjson, dataSource, ProConfigProvideMixin, this.createElementProxy, post, get, postForm,download)
        }
    },
    datas: {
        vcomponent: 'span',
        vjson: {}
    },
    props: {
        vjson: Object,
        //自定义render h函数
        createElementProxy: Function
    },
    render(h) {
        const _datas = {
            props: {
                ...this.$attrs
            },
            attrs: {
                ...this.$attrs
            },
            scopedSlots: this.$scopedSlots,
            on: this.$listeners
        }
        return h(this.vcomponent, _datas,Object.keys(this.$slots || {}).map(k => h('template', {slot: k}, [this.$slots[k]])), 'root')
    }
}