"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.ListItemMeta = exports.ListItemMetaProps = exports.ListItemProps = void 0;

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

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

var _classNames2 = _interopRequireDefault(require("../_util/classNames"));

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

var _grid = require("../grid");

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

var _index = require("./index");

var _vnode = require("../_util/vnode");

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; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

var ListItemProps = {
  prefixCls: _vueTypes.default.string,
  extra: _vueTypes.default.any,
  actions: _vueTypes.default.arrayOf(_vueTypes.default.any),
  grid: _index.ListGridType
};
exports.ListItemProps = ListItemProps;
var ListItemMetaProps = {
  avatar: _vueTypes.default.any,
  description: _vueTypes.default.any,
  prefixCls: _vueTypes.default.string,
  title: _vueTypes.default.any
};
exports.ListItemMetaProps = ListItemMetaProps;

var ListItemMeta = function ListItemMeta(props, _ref) {
  var _slots$avatar, _slots$title, _slots$description;

  var slots = _ref.slots;
  var configProvider = (0, _vue.inject)('configProvider', _configProvider.ConfigConsumerProps);
  var getPrefixCls = configProvider.getPrefixCls;
  var customizePrefixCls = props.prefixCls;
  var prefixCls = getPrefixCls('list', customizePrefixCls);
  var avatar = props.avatar || ((_slots$avatar = slots.avatar) === null || _slots$avatar === void 0 ? void 0 : _slots$avatar.call(slots));
  var title = props.title || ((_slots$title = slots.title) === null || _slots$title === void 0 ? void 0 : _slots$title.call(slots));
  var description = props.description || ((_slots$description = slots.description) === null || _slots$description === void 0 ? void 0 : _slots$description.call(slots));

  var content = _vue.createVNode("div", {
    "class": "".concat(prefixCls, "-item-meta-content")
  }, [title && _vue.createVNode("h4", {
    "class": "".concat(prefixCls, "-item-meta-title")
  }, [title]), description && _vue.createVNode("div", {
    "class": "".concat(prefixCls, "-item-meta-description")
  }, [description])]);

  return _vue.createVNode("div", {
    "class": "".concat(prefixCls, "-item-meta")
  }, [avatar && _vue.createVNode("div", {
    "class": "".concat(prefixCls, "-item-meta-avatar")
  }, [avatar]), (title || description) && content]);
};

exports.ListItemMeta = ListItemMeta;

_extends(ListItemMeta, {
  props: ListItemMetaProps,
  __ANT_LIST_ITEM_META: true,
  displayName: 'AListItemMeta'
});

function getGrid(grid, t) {
  return grid[t] && Math.floor(24 / grid[t]);
}

var _default2 = {
  name: 'AListItem',
  inheritAttrs: false,
  Meta: ListItemMeta,
  props: ListItemProps,
  setup: function setup() {
    var listContext = (0, _vue.inject)('listContext', {});
    var configProvider = (0, _vue.inject)('configProvider', _configProvider.ConfigConsumerProps);
    return {
      listContext: listContext,
      configProvider: configProvider
    };
  },
  methods: {
    isItemContainsTextNodeAndNotSingular: function isItemContainsTextNodeAndNotSingular() {
      var children = (0, _propsUtil.getSlot)(this) || [];
      var result;
      children.forEach(function (element) {
        if ((0, _propsUtil.isStringElement)(element) && !(0, _propsUtil.isEmptyElement)(element)) {
          result = true;
        }
      });
      return result && children.length > 1;
    },
    isFlexMode: function isFlexMode() {
      var extra = (0, _propsUtil.getComponent)(this, 'extra');
      var itemLayout = this.listContext.itemLayout;

      if (itemLayout === 'vertical') {
        return !!extra;
      }

      return !this.isItemContainsTextNodeAndNotSingular();
    }
  },
  render: function render() {
    var _this$listContext = this.listContext,
        grid = _this$listContext.grid,
        itemLayout = _this$listContext.itemLayout;
    var customizePrefixCls = this.prefixCls,
        $attrs = this.$attrs;

    var _className = $attrs.class,
        restAttrs = _objectWithoutProperties($attrs, ["class"]);

    var getPrefixCls = this.configProvider.getPrefixCls;
    var prefixCls = getPrefixCls('list', customizePrefixCls);
    var extra = (0, _propsUtil.getComponent)(this, 'extra');
    var actions = (0, _propsUtil.getComponent)(this, 'actions');
    actions = actions && !Array.isArray(actions) ? [actions] : actions;

    var actionsContent = actions && actions.length > 0 && _vue.createVNode("ul", {
      "class": "".concat(prefixCls, "-item-action"),
      "key": "actions"
    }, [actions.map(function (action, i) {
      return _vue.createVNode("li", {
        "key": "".concat(prefixCls, "-item-action-").concat(i)
      }, [action, i !== actions.length - 1 && _vue.createVNode("em", {
        "class": "".concat(prefixCls, "-item-action-split")
      }, null)]);
    })]);

    var children = (0, _propsUtil.getSlot)(this);
    var Tag = grid ? 'div' : 'li';

    var itemChildren = _vue.createVNode(Tag, _vue.mergeProps(restAttrs, {
      "class": (0, _classNames2.default)("".concat(prefixCls, "-item "), _className, _defineProperty({}, "".concat(prefixCls, "-item-no-flex"), !this.isFlexMode()))
    }), {
      default: function _default() {
        return [itemLayout === 'vertical' && extra ? [_vue.createVNode("div", {
          "class": "".concat(prefixCls, "-item-main"),
          "key": "content"
        }, [children, actionsContent]), _vue.createVNode("div", {
          "class": "".concat(prefixCls, "-item-extra"),
          "key": "extra"
        }, [extra])] : [children, actionsContent, (0, _vnode.cloneElement)(extra, {
          key: 'extra'
        })]];
      }
    });

    var mainContent = grid ? _vue.createVNode(_grid.Col, {
      "span": getGrid(grid, 'column'),
      "xs": getGrid(grid, 'xs'),
      "sm": getGrid(grid, 'sm'),
      "md": getGrid(grid, 'md'),
      "lg": getGrid(grid, 'lg'),
      "xl": getGrid(grid, 'xl'),
      "xxl": getGrid(grid, 'xxl')
    }, {
      default: function _default() {
        return [itemChildren];
      }
    }) : itemChildren;
    return mainContent;
  }
};
exports.default = _default2;