"use strict";

exports.__esModule = true;
exports.default = void 0;
var _tslib = require("tslib");
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _view = _interopRequireDefault(require("../../view"));
var _icon = _interopRequireDefault(require("../../icon"));
var _caption = _interopRequireDefault(require("./caption"));
var _content = _interopRequireDefault(require("./content"));
var _media = require("./media");
var _title = _interopRequireDefault(require("./title"));
var _utils = require("../../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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 _extends() { _extends = Object.assign ? Object.assign.bind() : 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 arrowIconMap = {
  right: 'arrow-right',
  up: 'arrow-up',
  down: 'arrow-down',
  loading: 'loading'
};
var renderExtra = function (ext) {
  if ((0, _utils.isString)(ext)) {
    return /*#__PURE__*/(0, _react.createElement)(_caption.default, null, ext);
  } else if (ext) {
    return ext;
  }
  return null;
};
var ListItem = function (props, ref) {
  var _classNames;
  var children = props.children,
    _props$prefix = props.prefix,
    prefix = _props$prefix === void 0 ? 'mt-' : _props$prefix,
    arrow = props.arrow,
    media = props.media,
    title = props.title,
    subTitle = props.subTitle,
    description = props.description,
    extra = props.extra,
    className = props.className,
    _onClick = props.onClick,
    _props$disabled = props.disabled,
    disabled = _props$disabled === void 0 ? false : _props$disabled,
    others = (0, _tslib.__rest)(props, ["children", "prefix", "arrow", "media", "title", "subTitle", "description", "extra", "className", "onClick", "disabled"]);
  return /*#__PURE__*/(0, _react.createElement)(_view.default, _extends({}, others, {
    className: (0, _classnames.default)(prefix + "list-item", (_classNames = {}, _classNames[prefix + "list-item--clickable"] = (0, _utils.isFunction)(_onClick), _classNames[prefix + "list-item--disabled"] = disabled, _classNames), className),
    ref: ref,
    onClick: function onClick() {
      if (!disabled && _onClick) {
        _onClick.apply(void 0, arguments);
      }
    }
  }), media ? /*#__PURE__*/(0, _react.createElement)(_media.ListItemMedia, null, media) : null, /*#__PURE__*/(0, _react.createElement)(_view.default, {
    className: prefix + "list-item-container"
  }, title || description ? /*#__PURE__*/(0, _react.createElement)(_content.default, null, title ? /*#__PURE__*/(0, _react.createElement)(_title.default, null, title) : null, subTitle ? /*#__PURE__*/(0, _react.createElement)(_caption.default, null, subTitle) : null, description ? /*#__PURE__*/(0, _react.createElement)(_caption.default, null, description) : null) : null, extra || (0, _utils.isString)(arrow) ? /*#__PURE__*/(0, _react.createElement)(_media.ListItemAction, null, renderExtra(extra), (0, _utils.isString)(arrow) ? /*#__PURE__*/(0, _react.createElement)(_icon.default, {
    size: "xs",
    className: prefix + "list-item-icon",
    name: arrowIconMap[arrow]
  }) : null) : null, children));
};
ListItem.displayName = 'ListItem';
var _default = /*#__PURE__*/(0, _react.forwardRef)(ListItem);
exports.default = _default;