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", "counter", "forwardedRef", "size", "onClick"];
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
import PropTypes from 'prop-types';
import Box from '../box';
import cx from 'classnames';
import theme from './theme.css';
import { Heading4, Heading5 } from '../typography';
/** @type {React.ComponentType<any>} */

var TitleTab = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var active = _ref.active,
      children = _ref.children,
      className = _ref.className,
      _ref$counter = _ref.counter,
      counter = _ref$counter === void 0 ? null : _ref$counter,
      forwardedRef = _ref.forwardedRef,
      size = _ref.size,
      onClick = _ref.onClick,
      others = _objectWithoutProperties(_ref, _excluded);

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

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

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

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

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

  var getPaddingHorizontal = function getPaddingHorizontal() {
    switch (size) {
      case 'small':
        return 2;

      case 'medium':
      default:
        return 3;
    }
  };

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