import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["onMouseUp", "onMouseLeave", "children", "className", "active", "label"];

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

import React, { useRef, forwardRef, useImperativeHandle } from 'react';
import Box from '../box';
import { UITextBody } from '../typography';
import cx from 'classnames';
import theme from './theme.css';
var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var onMouseUp = _ref.onMouseUp,
      onMouseLeave = _ref.onMouseLeave,
      children = _ref.children,
      _ref$className = _ref.className,
      className = _ref$className === void 0 ? '' : _ref$className,
      active = _ref.active,
      label = _ref.label,
      others = _objectWithoutProperties(_ref, _excluded);

  var buttonRef = useRef(null);
  useImperativeHandle(ref, function () {
    return buttonRef.current;
  });

  var blur = function blur() {
    var currentButtonRef = buttonRef.current;

    if (currentButtonRef) {
      currentButtonRef.blur();
    }
  };

  var handleMouseUp = function handleMouseUp(event) {
    blur();

    if (onMouseUp) {
      onMouseUp(event);
    }
  };

  var handleMouseLeave = function handleMouseLeave(event) {
    blur();

    if (onMouseLeave) {
      onMouseLeave(event);
    }
  };

  var classNames = cx(theme['reset-box-sizing'], theme['reset-font-smoothing'], theme['button-base'], theme['button'], _defineProperty({}, theme['is-active'], active), className);

  var props = _objectSpread(_objectSpread({}, others), {}, {
    ref: buttonRef,
    className: classNames,
    element: 'button',
    onMouseUp: handleMouseUp,
    onMouseLeave: handleMouseLeave,
    'data-teamleader-ui': 'button'
  });

  return /*#__PURE__*/React.createElement(Box, props, (label || children) && /*#__PURE__*/React.createElement(UITextBody, {
    element: "span",
    maxLines: 1
  }, label, children));
});
Button.displayName = 'MarketingButtonGroup.Button';
export default Button;