// 自定义图片上传组件
import React, { useContext } from 'react';
import { ContentUtils } from 'braft-utils';
import { PictureFilled } from '@ant-design/icons';
import { ConfigContext } from "../config-provider/context";
import Upload from "../upload";
var ImageUploader = function ImageUploader(_ref) {
  var setEditorState = _ref.setEditorState,
    editorState = _ref.editorState;
  var _useContext = useContext(ConfigContext),
    uiLocale = _useContext.uiLocale;

  // 图片上传
  var onUpload = function onUpload(_, file) {
    if (!file) return;
    if (file.status === 'done') {
      var _file$response;
      setEditorState(ContentUtils.insertMedias(editorState, [{
        type: 'IMAGE',
        url: (_file$response = file.response) === null || _file$response === void 0 ? void 0 : _file$response.url
      }]));
    }
  };
  return /*#__PURE__*/React.createElement(Upload, {
    accept: "image/*",
    onChange: onUpload,
    showUploadList: false
  }, /*#__PURE__*/React.createElement("button", {
    type: "button",
    "data-title": uiLocale.BraftEditor.insertImage,
    className: "control-item button"
  }, /*#__PURE__*/React.createElement(PictureFilled, null)));
};
export default ImageUploader;