"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 _Heading = _interopRequireDefault(require("../Heading"));
var _Icon = _interopRequireWildcard(require("../Icon"));
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (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; }
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

/**
 * `Media` component is a combination of icon, text title and content.
 * This layout was so widely spread in our products so we have decided to create a special component for it.
 * Probably we should have named the component differently (not Media), but we didn't have better idea then ;)
 * @since 0.0.45
 */
const Media = _ref => {
  let {
    className,
    children,
    title,
    titleAddon,
    titleSize,
    image,
    imageSpacing,
    imageAlign,
    align,
    vertical = false,
    baseClassName = `${_constants.CLS_PREFIX}media`,
    ...props
  } = _ref;
  if (!imageSpacing && /*#__PURE__*/(0, _react.isValidElement)(image) && image.type === _Icon.default) {
    const map = {
      [_Icon.ICON_SIZE_12]: 'sm',
      [_Icon.ICON_SIZE_16]: 'sm',
      [_Icon.ICON_SIZE_24]: 'md',
      [_Icon.ICON_SIZE_32]: 'md',
      [_Icon.ICON_SIZE_48]: 'lg',
      [_Icon.ICON_SIZE_64]: 'xl',
      [_Icon.ICON_SIZE_96]: 'xxl',
      [_Icon.ICON_SIZE_128]: 'xxl',
      [_Icon.ICON_SIZE_192]: 'xxl'
    };
    imageSpacing = map[image.props.size];
  }
  const renderTitle = title => {
    if (!title) {
      return null;
    }
    if (typeof title === 'string') {
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Heading.default, {
        level: 5,
        className: `${baseClassName}__title`,
        children: title
      });
    }
    if ( /*#__PURE__*/(0, _react.isValidElement)(title)) {
      return /*#__PURE__*/(0, _react.cloneElement)(title, {
        className: (0, _classnames.default)(`${baseClassName}__title`, title.props.className)
      });
    }
    return null;
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: (0, _classnames.default)(baseClassName, {
      [`${baseClassName}--${align}`]: align,
      [`${baseClassName}--vertical`]: vertical
    }, className),
    ...props,
    children: [image && /*#__PURE__*/(0, _jsxRuntime.jsx)("figure", {
      className: (0, _classnames.default)(`${baseClassName}__figure`, {
        [`${baseClassName}__figure--${imageSpacing}`]: imageSpacing,
        [`${baseClassName}__figure--${imageAlign}`]: imageAlign
      }),
      children: image
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: `${baseClassName}__body`,
      children: [title || titleAddon ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: (0, _classnames.default)(`${baseClassName}__header`, {
          [`${baseClassName}__header--${titleSize}`]: titleSize
        }),
        children: [renderTitle(title), titleAddon && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: `${baseClassName}__title-addon`,
          children: titleAddon
        })]
      }) : null, _react.Children.toArray(children).length ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: `${baseClassName}__content`,
        children: children
      }) : null]
    })]
  });
};
var _default = exports.default = Media;