'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var base = require('./variations/_view/base.js');
var base$1 = require('./variations/_size/base.js');
var base$2 = require('./variations/_disabled/base.js');
var LinkButton_styles = require('./LinkButton.styles.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var _StyledSpinner;
var _excluded = ["children", "view", "size", "text", "contentLeft", "contentRight", "isLoading", "loader", "disabled", "target", "href", "rel", "style", "additionalContent", "onClick"];
var linkButtonRoot = function linkButtonRoot(Root) {
  return /*#__PURE__*/React.forwardRef(function (props, ref) {
    var children = props.children,
      view = props.view,
      size = props.size,
      text = props.text,
      contentLeft = props.contentLeft,
      contentRight = props.contentRight,
      isLoading = props.isLoading,
      loader = props.loader,
      disabled = props.disabled,
      target = props.target,
      href = props.href,
      rel = props.rel,
      style = props.style,
      additionalContent = props.additionalContent,
      onClick = props.onClick,
      rest = _rollupPluginBabelHelpers.objectWithoutProperties(props, _excluded);
    var txt = typeof children === 'string' ? children : text;
    var loadingCustomOpacity = isLoading && size === 'xxs' && {
      opacity: 0
    };
    var linkProps = {
      target: target,
      href: disabled ? undefined : href,
      rel: target === '_blank' ? 'noopener noreferrer' : rel
    };
    var hasContent = Boolean(txt || children || additionalContent || contentRight);
    var handleClick = function handleClick(e) {
      if (disabled || isLoading) {
        e.preventDefault();
        e.stopPropagation();
        return;
      }
      if (onClick) {
        onClick(e);
      }
    };
    return /*#__PURE__*/React__default.default.createElement(Root, _rollupPluginBabelHelpers.extends({
      ref: ref,
      view: view,
      size: size,
      tabIndex: !disabled ? 0 : -1,
      disabled: disabled,
      style: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, isLoading && {
        pointerEvents: 'none'
      }), style),
      onClick: handleClick
    }, linkProps, rest), /*#__PURE__*/React__default.default.createElement(LinkButton_styles.LoadWrap, {
      isLoading: !disabled && isLoading,
      style: _rollupPluginBabelHelpers.objectSpread2({}, loadingCustomOpacity)
    }, contentLeft && /*#__PURE__*/React__default.default.createElement(LinkButton_styles.StyledContentLeft, {
      hasContent: hasContent
    }, contentLeft), txt ? /*#__PURE__*/React__default.default.createElement(LinkButton_styles.LinkButtonText, null, txt) : children, additionalContent && /*#__PURE__*/React__default.default.createElement(LinkButton_styles.StyledAdditionalContent, null, additionalContent), contentRight && /*#__PURE__*/React__default.default.createElement(LinkButton_styles.StyledContentRight, {
      hasContent: hasContent
    }, contentRight)), !disabled && isLoading && /*#__PURE__*/React__default.default.createElement(LinkButton_styles.Loader, null, loader || _StyledSpinner || (_StyledSpinner = /*#__PURE__*/React__default.default.createElement(LinkButton_styles.StyledSpinner, null))));
  });
};
var linkButtonConfig = {
  name: 'LinkButton',
  tag: 'a',
  layout: linkButtonRoot,
  base: LinkButton_styles.base,
  variations: {
    view: {
      css: base.base
    },
    size: {
      css: base$1.base
    },
    disabled: {
      css: base$2.base,
      attrs: true
    }
  },
  defaults: {
    view: 'default',
    size: 'm'
  }
};

exports.linkButtonConfig = linkButtonConfig;
exports.linkButtonRoot = linkButtonRoot;
