import _extends from "@babel/runtime/helpers/extends";
import * as React from 'react';
import { Button } from '@megafon/ui-core';
import { cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
import { setRelAttribute } from "../../helpers/setRelAttribute";
import "./ButtonsBox.css";
var cn = cnCreate('mfui-9-buttons-box');
var ButtonsBox = function ButtonsBox(_ref) {
  var className = _ref.className,
    _ref$classes = _ref.classes,
    classes = _ref$classes === void 0 ? {} : _ref$classes,
    dataAttrs = _ref.dataAttrs,
    button = _ref.button,
    extraButton = _ref.extraButton,
    align = _ref.align,
    rootRef = _ref.rootRef;
  var showTwoButtons = !!button && !!extraButton;
  var renderButton = function renderButton(btnProps, btnClassName, dataAttr) {
    return /*#__PURE__*/React.createElement(Button, {
      dataAttrs: {
        root: dataAttr
      },
      className: btnClassName,
      fullWidth: showTwoButtons,
      type: btnProps.type,
      theme: "green",
      icon: btnProps.icon,
      href: btnProps.href,
      target: btnProps.target,
      download: btnProps.download,
      showArrow: btnProps.showArrow,
      rel: setRelAttribute(btnProps.rel, btnProps.target),
      onClick: btnProps.onClick
    }, btnProps.title);
  };
  return /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
    className: cn({
      'h-align': align
    }, [className, classes.root]),
    ref: rootRef
  }), /*#__PURE__*/React.createElement("div", {
    className: cn('buttons', {
      'equal-width': showTwoButtons
    })
  }, !!button && renderButton(button, classes.button, dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.button), !!extraButton && renderButton(extraButton, classes.extraButton, dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.extraButton)));
};
export default ButtonsBox;