import _extends from "@babel/runtime/helpers/extends";
import "core-js/modules/es.symbol.js";
import "core-js/modules/es.symbol.description.js";
import * as React from 'react';
import { Header, Paragraph, Button } from '@megafon/ui-core';
import { cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
import { setRelAttribute } from "../../helpers/setRelAttribute";
import "./TitleDescriptionBox.css";
var cn = cnCreate('mfui-9-title-description-box');
var TitleDescriptionBox = function TitleDescriptionBox(_ref) {
  var dataAttrs = _ref.dataAttrs,
    title = _ref.title,
    description = _ref.description,
    textColor = _ref.textColor,
    align = _ref.align,
    button = _ref.button,
    rootRef = _ref.rootRef,
    className = _ref.className,
    _ref$classes = _ref.classes,
    classes = _ref$classes === void 0 ? {} : _ref$classes;
  var hasButton = !!(button === null || button === void 0 ? void 0 : button.title);
  var renderDescription = React.useCallback(function () {
    if (typeof description === 'string') {
      return /*#__PURE__*/React.createElement(Paragraph, {
        className: cn('item'),
        hasMargin: false,
        color: "inherit"
      }, description);
    }
    return /*#__PURE__*/React.createElement("div", {
      className: cn('description')
    }, description);
  }, [description]);
  return /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
    className: cn({
      'h-align': align,
      'text-color': textColor,
      'with-button': hasButton
    }, [className, classes.root]),
    ref: rootRef
  }), /*#__PURE__*/React.createElement("div", {
    className: cn('text-content')
  }, title && /*#__PURE__*/React.createElement(Header, {
    className: cn('item', {
      header: true
    }),
    as: "h2",
    color: "inherit"
  }, title), description && renderDescription()), hasButton && /*#__PURE__*/React.createElement(Button, {
    className: cn('button', [classes.button]),
    dataAttrs: {
      root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.button
    },
    type: "primary",
    theme: "green",
    sizeAll: "large",
    fullWidthMobile: true,
    icon: button.icon,
    href: button.href,
    target: button.target,
    download: button.download,
    showArrow: button.showArrow,
    rel: setRelAttribute(button.rel, button.target),
    onClick: button.onClick
  }, button.title));
};
export default TitleDescriptionBox;