import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["active", "children", "className", "size", "onClick"];
import React, { forwardRef, useRef, useImperativeHandle } from 'react';
import cx from 'classnames';
import theme from './theme.css';
import Box from '../box';
import MarketingLockBadge from '../marketingLockBadge';
import { Heading4, Heading5 } from '../typography';
var MarketingTab = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var _ref$active = _ref.active,
      active = _ref$active === void 0 ? false : _ref$active,
      children = _ref.children,
      className = _ref.className,
      _ref$size = _ref.size,
      size = _ref$size === void 0 ? 'medium' : _ref$size,
      onClick = _ref.onClick,
      others = _objectWithoutProperties(_ref, _excluded);

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

  var blur = function blur() {
    var currentTabRef = tabRef.current;

    if (currentTabRef !== null && currentTabRef !== void 0 && currentTabRef.blur) {
      currentTabRef.blur();
    }
  };

  var handleClick = function handleClick(event) {
    if (onClick) {
      onClick(event);
    }

    if (event.pageX !== 0 && event.pageY !== 0) {
      blur();
    }
  };

  var classNames = cx(theme['wrapper'], _defineProperty({}, theme['is-active'], active), className);
  var TextElement = size === 'small' ? Heading5 : Heading4;
  return /*#__PURE__*/React.createElement(Box, _extends({
    "data-teamleader-ui": "marketing-tab",
    className: classNames,
    marginHorizontal: size === 'small' ? 1 : 2,
    paddingHorizontal: size === 'small' ? 2 : 3,
    ref: tabRef,
    onClick: handleClick
  }, others), /*#__PURE__*/React.createElement(TextElement, {
    element: "span"
  }, children), /*#__PURE__*/React.createElement(MarketingLockBadge, {
    marginLeft: 3,
    size: size
  }));
});
MarketingTab.displayName = 'MarketingTab';
export default MarketingTab;