import * as _vue from "vue";
import { inject } from 'vue';
import PropsTypes from '../_util/vue-types';
import { getComponent, getSlot } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
export var CommentProps = {
  actions: PropsTypes.array,

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

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

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

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

  /** A datetime element containing the time to be displayed */
  datetime: PropsTypes.any
};
var Comment = {
  name: 'AComment',
  props: CommentProps,
  setup: function setup() {
    return {
      configProvider: inject('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 = getComponent(this, 'actions');
    var author = getComponent(this, 'author');
    var avatar = getComponent(this, 'avatar');
    var content = getComponent(this, 'content');
    var datetime = 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 = 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);
};

export default Comment;