"use strict";

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

var firstLaterUpperCase = function firstLaterUpperCase(str) {
  var temp = str.split("");

  if (temp.length > 0) {
    temp[0] = temp[0].toUpperCase();
    return temp.join('');
  }

  return '';
};

var formatAttachments = function formatAttachments(data) {
  if (!data) return [];
  return data.map(function (item) {
    var tempObj = {};
    Object.keys(item).forEach(function (key) {
      tempObj[firstLaterUpperCase(key)] = item[key];
    });
    return tempObj;
  });
}; // 获取富文本某个类型的内容


exports.formatAttachments = formatAttachments;

var getTypeContent = function getTypeContent(data, initType) {
  var type = data.type,
      content = data.content;

  if (type === initType) {
    return data;
  } else {
    if (content !== null && content !== void 0 && content.length) {
      for (var i = 0; i < (content === null || content === void 0 ? void 0 : content.length); i++) {
        return getTypeContent(content[i], initType);
      }
    }

    return null;
  }
};

var isEmptyImage = function isEmptyImage(richText) {
  if (!richText) return true;
  richText = JSON.parse(richText || '{}');
  var _richText = richText,
      doc = _richText.doc;
  var bol = true;

  if (doc) {
    var _imageData$attrs;

    var imageData = getTypeContent(doc, 'image');
    bol = !(imageData !== null && imageData !== void 0 && (_imageData$attrs = imageData.attrs) !== null && _imageData$attrs !== void 0 && _imageData$attrs.src);
  }

  return bol;
};

exports.isEmptyImage = isEmptyImage;