"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.SimpleCmsEditorComponentImage = void 0;

var _react = _interopRequireDefault(require("react"));

var _react2 = require("@emotion/react");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const image = {
  label: 'Image',
  id: 'image',
  fromBlock: match => match && {
    image: match[2],
    alt: match[1],
    title: match[4]
  },
  toBlock: _ref => {
    let {
      alt,
      image,
      title
    } = _ref;
    return `![${alt || ''}](${image || ''}${title ? ` "${title.replace(/"/g, '\\"')}"` : ''})`;
  },
  // eslint-disable-next-line react/display-name
  toPreview: (_ref2, getAsset, fields) => {
    let {
      alt,
      image,
      title
    } = _ref2;
    const imageField = fields === null || fields === void 0 ? void 0 : fields.find(f => f.get('widget') === 'image');
    const src = getAsset(image, imageField);
    return (0, _react2.jsx)("img", {
      src: src || '',
      alt: alt || '',
      title: title || ''
    });
  },
  pattern: /^!\[(.*)\]\((.*?)(\s"(.*)")?\)$/,
  fields: [{
    label: 'Image',
    name: 'image',
    widget: 'image',
    media_library: {
      allow_multiple: false
    }
  }, {
    label: 'Alt Text',
    name: 'alt'
  }, {
    label: 'Title',
    name: 'title'
  }]
};
const SimpleCmsEditorComponentImage = image;
exports.SimpleCmsEditorComponentImage = SimpleCmsEditorComponentImage;
var _default = image;
exports.default = _default;