"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _constants = require("../../constants");
var _Icon = _interopRequireWildcard(require("../Icon"));
var _Media = _interopRequireDefault(require("../Media"));
var _Heading = _interopRequireDefault(require("../Heading"));
var _Tooltip = _interopRequireDefault(require("../Tooltip"));
var _utils = require("../utils");
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
// Copyright 1999-2025. WebPros International GmbH. All rights reserved.

/**
 * `Item` component is element of [ItemList](#!/ItemList) and it is presented as
 * a combination of icon, text title and content (similar to [Media](#!/Media)).
 * @since 0.0.48
 */
const Item = _ref => {
  let {
    children,
    baseClassName = `${_constants.CLS_PREFIX}item`,
    component,
    view = 'simple',
    className,
    icon,
    title,
    description,
    footer,
    value,
    tooltip,
    disabled,
    hoverable,
    ...props
  } = _ref;
  const Tag = component || 'div';
  const renderTitle = () => {
    if (!title) {
      return null;
    }
    let wrappable = false;
    if (typeof title === 'string') {
      title = /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
        children: title
      });
      wrappable = true;
    } else if (typeof title === 'object' && ! /*#__PURE__*/(0, _react.isValidElement)(title)) {
      title = /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
        ...title
      });
      wrappable = true;
    }
    if (wrappable && view === 'card') {
      title = /*#__PURE__*/(0, _jsxRuntime.jsx)(_Heading.default, {
        level: 3,
        children: title
      });
    }
    if (/*#__PURE__*/(0, _react.isValidElement)(title)) {
      title = /*#__PURE__*/(0, _react.cloneElement)(title, {
        className: (0, _classnames.default)(`${baseClassName}__title`, title.props.className)
      });
    }
    return title;
  };
  const renderIcon = () => {
    if (!icon) {
      return null;
    }
    if (typeof icon === 'string') {
      return _Icon.default.create({}, {
        size: _Icon.ICON_SIZE_32,
        [_Icon.NAMES.indexOf(icon) === -1 ? 'src' : 'name']: icon
      });
    }
    return _Icon.default.create(icon, {
      size: _Icon.ICON_SIZE_32
    });
  };
  if (props.onClick) {
    if (disabled) {
      props.onClick = e => e.preventDefault();
    } else {
      props.tabIndex = 0;
      props.onKeyDown = (0, _utils.wrapFunction)(props.onKeyDown, e => {
        if (e.key === 'Enter') {
          e.preventDefault();
          e.currentTarget.click();
        }
      });
    }
  }
  const item = /*#__PURE__*/(0, _jsxRuntime.jsxs)(Tag, {
    className: (0, _classnames.default)(baseClassName, {
      [`${baseClassName}--card`]: view === 'card',
      [`${baseClassName}--disabled`]: disabled,
      [`${baseClassName}--hoverable`]: hoverable
    }, className),
    ...props,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Media.default, {
      image: renderIcon(),
      title: renderTitle(),
      className: `${baseClassName}__media`,
      children: [description && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: `${baseClassName}__description`,
        children: description
      }), _react.Children.toArray(children).length ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: `${baseClassName}__content`,
        children: children
      }) : null]
    }), footer && /*#__PURE__*/(0, _jsxRuntime.jsx)("footer", {
      className: `${baseClassName}__footer`,
      children: footer
    })]
  });
  if (tooltip) {
    return (0, _utils.createProxyProps)(props => /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
      title: tooltip,
      children: /*#__PURE__*/(0, _react.cloneElement)(item, props)
    }));
  }
  return item;
};
var _default = exports.default = Item;