import React from 'react'
import ReactUeditor from '@/components/Editor/ReactUeditor'
import { uploadImagePlugin, uploadVidioPlugin, uploadWeChatImagePlugin, uploadWeChatCardPlugin, uploadALink } from './editorPlugin'

export default function UEditor(props:{dispatch: (arg: any) => void,setLoding: (arg: boolean) => void,isOk: (arg: any) => void,setContent:(arg:any)=>void,isShowWx:any}) {
    let {dispatch,setLoding,isOk,setContent,isShowWx} = props
    return <ReactUeditor
        ueditorPath={`/ueditor`}
        getRef={(ref: any) => {
            dispatch({ type: 'setRef', params: { ueditorRef: ref } })//存放实例
        }}
        onReady={
            (ueditor: any) => {
                setLoding(false)
                isOk(ueditor)//执行编辑的操作
            }
        }
        plugins={[
            'emotion',
            (e: any) => { return uploadImagePlugin(e, isShowWx) },
            uploadVidioPlugin,
            uploadWeChatImagePlugin,
            uploadWeChatCardPlugin,
            uploadALink
        ]}
        onChange={(content: any) => {
            if (content || '<p></p>') {
                setContent(content)
            }
        }}
    />
}