import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2, extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
import { jsx } from '@emotion/core';
import React__default from 'react';
import { BaseAnchor } from '../BaseAnchor/BaseAnchor.esm.js';
import _pt from 'prop-types';
import { BaseButton } from '../BaseButton/BaseButton.esm.js';
import { getButtonStyles } from '../Button/Button.esm.js';
import { BaseLink } from '../BaseLink/BaseLink.esm.js';
import { visuallyHiddenCss } from '../../stylesheets/a11y.esm.js';

var baseCss = function baseCss(_theme) {
  return {
    paddingLeft: 0,
    paddingRight: 0,
    paddingTop: 0,
    paddingBottom: 0,
    // override default styles from getButtonStyles
    svg: {
      margin: 0
    }
  };
};

var iconSizeStyles = {
  S: function S(theme) {
    return {
      fontSize: theme.fontSizes[4]
    };
  },
  M: function M(theme) {
    return {
      fontSize: theme.fontSizes[5]
    };
  },
  L: function L(theme) {
    return {
      fontSize: theme.fontSizes[6]
    };
  },
  XL: function XL(theme) {
    return {
      fontSize: theme.fontSizes[7]
    };
  }
};

function IconButtonLabel(_ref) {
  var icon = _ref.icon,
      children = _ref.children;
  return jsx(React__default.Fragment, null, jsx("span", {
    css: visuallyHiddenCss
  }, children), icon);
}

IconButtonLabel.propTypes = {
  icon: _pt.node.isRequired,
  children: _pt.node.isRequired
};
var IconButton = React__default.forwardRef(function IconButton(props, ref) {
  var icon = props.icon,
      children = props.children,
      size = props.size,
      tone = props.tone,
      variant = props.variant,
      rest = _objectWithoutProperties(props, ["icon", "children", "size", "tone", "variant"]);

  var iconButtonProps = useIconButton({
    icon: icon,
    children: children,
    size: size,
    tone: tone,
    variant: variant
  });
  return jsx(BaseButton, _extends({}, iconButtonProps, rest, {
    ref: ref
  }));
});
IconButton.propTypes = {
  icon: _pt.node.isRequired,
  children: _pt.node.isRequired
};
var IconAnchorButton = React__default.forwardRef(function IconAnchorButton(props, ref) {
  var icon = props.icon,
      children = props.children,
      size = props.size,
      tone = props.tone,
      variant = props.variant,
      rest = _objectWithoutProperties(props, ["icon", "children", "size", "tone", "variant"]);

  var iconButtonProps = useIconButton({
    icon: icon,
    children: children,
    size: size,
    tone: tone,
    variant: variant
  });
  return jsx(BaseAnchor, _extends({}, iconButtonProps, rest, {
    ref: ref
  }));
});
IconAnchorButton.propTypes = {
  icon: _pt.node.isRequired,
  children: _pt.node.isRequired
};
function IconLinkButton(props) {
  var icon = props.icon,
      children = props.children,
      size = props.size,
      tone = props.tone,
      variant = props.variant,
      rest = _objectWithoutProperties(props, ["icon", "children", "size", "tone", "variant"]);

  var iconButtonProps = useIconButton({
    icon: icon,
    children: children,
    size: size,
    tone: tone,
    variant: variant
  });
  return jsx(BaseLink, _extends({}, iconButtonProps, rest));
}
IconLinkButton.propTypes = {
  icon: _pt.node.isRequired,
  children: _pt.node.isRequired
};

function useIconButton(_ref2) {
  var icon = _ref2.icon,
      children = _ref2.children,
      _ref2$size = _ref2.size,
      size = _ref2$size === void 0 ? "L" : _ref2$size,
      tone = _ref2.tone,
      variant = _ref2.variant;

  var _getButtonStyles = getButtonStyles({
    children: jsx(IconButtonLabel, {
      icon: icon
    }, children),
    loading: false,
    size: size,
    tone: tone,
    variant: variant,
    leftIcon: null,
    rightIcon: null,
    textVariant: "DEFAULT"
  }),
      css = _getButtonStyles.css,
      styledButtonProps = _objectWithoutProperties(_getButtonStyles, ["css"]);

  var finalCss = function finalCss(theme) {
    return [css(theme), baseCss(), iconSizeStyles[size](theme)];
  };

  return _objectSpread2({}, styledButtonProps, {
    css: finalCss
  });
}

IconButton.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "IconButton"
};

if (typeof STORYBOOK_REACT_CLASSES !== "undefined") {
  STORYBOOK_REACT_CLASSES["src/components/IconButton/IconButton.tsx"] = {
    name: "IconButton",
    docgenInfo: IconButton.__docgenInfo,
    path: "src/components/IconButton/IconButton.tsx"
  };
}

IconAnchorButton.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "IconAnchorButton"
};

if (typeof STORYBOOK_REACT_CLASSES !== "undefined") {
  STORYBOOK_REACT_CLASSES["src/components/IconButton/IconButton.tsx"] = {
    name: "IconAnchorButton",
    docgenInfo: IconAnchorButton.__docgenInfo,
    path: "src/components/IconButton/IconButton.tsx"
  };
}

IconLinkButton.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "IconLinkButton",
  "props": {
    "icon": {
      "required": true,
      "tsType": {
        "name": "ReactReactNode",
        "raw": "React.ReactNode"
      },
      "description": ""
    },
    "children": {
      "required": true,
      "tsType": {
        "name": "ReactReactNode",
        "raw": "React.ReactNode"
      },
      "description": ""
    },
    "size": {
      "required": false,
      "tsType": {
        "name": "ButtonSize"
      },
      "description": ""
    }
  }
};

if (typeof STORYBOOK_REACT_CLASSES !== "undefined") {
  STORYBOOK_REACT_CLASSES["src/components/IconButton/IconButton.tsx"] = {
    name: "IconLinkButton",
    docgenInfo: IconLinkButton.__docgenInfo,
    path: "src/components/IconButton/IconButton.tsx"
  };
}

export { IconAnchorButton, IconButton, IconLinkButton };
//# sourceMappingURL=IconButton.esm.js.map
