"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

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

var _vue = _interopRequireWildcard(require("vue"));

var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));

var _propsUtil = require("../_util/props-util");

var _configProvider = require("../config-provider");

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var CommentProps = {
  actions: _vueTypes.default.array,

  /** The element to display as the comment author. */
  author: _vueTypes.default.any,

  /** The element to display as the comment avatar - generally an antd Avatar */
  avatar: _vueTypes.default.any,

  /** The main content of the comment */
  content: _vueTypes.default.any,

  /** Comment prefix defaults to '.ant-comment' */
  prefixCls: _vueTypes.default.string,

  /** A datetime element containing the time to be displayed */
  datetime: _vueTypes.default.any
};
exports.CommentProps = CommentProps;
var Comment = {
  name: 'AComment',
  props: CommentProps,
  setup: function setup() {
    return {
      configProvider: (0, _vue.inject)('configProvider', _configProvider.ConfigConsumerProps)
    };
  },
  methods: {
    getAction: function getAction(actions) {
      if (!actions || !actions.length) {
        return null;
      }

      var actionList = actions.map(function (action, index) {
        return _vue.createVNode("li", {
          "key": "action-".concat(index)
        }, [action]);
      });
      return actionList;
    },
    renderNested: function renderNested(prefixCls, children) {
      return _vue.createVNode("div", {
        "class": "".concat(prefixCls, "-nested")
      }, [children]);
    }
  },
  render: function render() {
    var customizePrefixCls = this.$props.prefixCls;
    var getPrefixCls = this.configProvider.getPrefixCls;
    var prefixCls = getPrefixCls('comment', customizePrefixCls);
    var actions = (0, _propsUtil.getComponent)(this, 'actions');
    var author = (0, _propsUtil.getComponent)(this, 'author');
    var avatar = (0, _propsUtil.getComponent)(this, 'avatar');
    var content = (0, _propsUtil.getComponent)(this, 'content');
    var datetime = (0, _propsUtil.getComponent)(this, 'datetime');

    var avatarDom = _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-avatar")
    }, [typeof avatar === 'string' ? _vue.createVNode("img", {
      "src": avatar,
      "alt": "comment-avatar"
    }, null) : avatar]);

    var actionDom = actions ? _vue.createVNode("ul", {
      "class": "".concat(prefixCls, "-actions")
    }, [this.getAction(Array.isArray(actions) ? actions : [actions])]) : null;

    var authorContent = _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-content-author")
    }, [author && _vue.createVNode("span", {
      "class": "".concat(prefixCls, "-content-author-name")
    }, [author]), datetime && _vue.createVNode("span", {
      "class": "".concat(prefixCls, "-content-author-time")
    }, [datetime])]);

    var contentDom = _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-content")
    }, [authorContent, _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-content-detail")
    }, [content]), actionDom]);

    var comment = _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-inner")
    }, [avatarDom, contentDom]);

    var children = (0, _propsUtil.getSlot)(this);
    return _vue.createVNode("div", {
      "class": prefixCls
    }, [comment, children && children.length ? this.renderNested(prefixCls, children) : null]);
  }
};
/* istanbul ignore next */

Comment.install = function (app) {
  app.component(Comment.name, Comment);
};

var _default = Comment;
exports.default = _default;