import DgEditor from './src/main.vue'
// 为组件提供 install 安装方法，供按需引入
DgEditor.install = function (app) {
  app.component(DgEditor.name, DgEditor)
}
export default DgEditor

const renderEditor = (h, option, form) => {
  const { editor, editorProps = {}, className = '', prop } = option
  const { slots = {}, style = {}, class: _className = '', on = {}, ...attrs } = editorProps

  const props = { style, class: ['dg-editor'].concat([className, _className]), attrs, on }

  if (editor === 'dg-text') {
    props.class.push('dg-text')
    return h('span', props, [form[prop]])
  }

  return h(
    editor,
    props,
    Object.entries(slots).map(([slot, render]) => h({ render }, { slot }))
  )
}

export { DgEditor, renderEditor }
