import { objectWithoutProperties as _objectWithoutProperties, extends as _extends, objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
import React__default, { forwardRef } from 'react';
import { base as base$1 } from './variations/_view/base.js';
import { base as base$2 } from './variations/_size/base.js';
import { base as base$3 } from './variations/_disabled/base.js';
import { LoadWrap, StyledContentLeft, LinkButtonText, StyledAdditionalContent, StyledContentRight, Loader, StyledSpinner, base } from './LinkButton.styles.js';

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__*/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 = _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.createElement(Root, _extends({
      ref: ref,
      view: view,
      size: size,
      tabIndex: !disabled ? 0 : -1,
      disabled: disabled,
      style: _objectSpread2(_objectSpread2({}, isLoading && {
        pointerEvents: 'none'
      }), style),
      onClick: handleClick
    }, linkProps, rest), /*#__PURE__*/React__default.createElement(LoadWrap, {
      isLoading: !disabled && isLoading,
      style: _objectSpread2({}, loadingCustomOpacity)
    }, contentLeft && /*#__PURE__*/React__default.createElement(StyledContentLeft, {
      hasContent: hasContent
    }, contentLeft), txt ? /*#__PURE__*/React__default.createElement(LinkButtonText, null, txt) : children, additionalContent && /*#__PURE__*/React__default.createElement(StyledAdditionalContent, null, additionalContent), contentRight && /*#__PURE__*/React__default.createElement(StyledContentRight, {
      hasContent: hasContent
    }, contentRight)), !disabled && isLoading && /*#__PURE__*/React__default.createElement(Loader, null, loader || _StyledSpinner || (_StyledSpinner = /*#__PURE__*/React__default.createElement(StyledSpinner, null))));
  });
};
var linkButtonConfig = {
  name: 'LinkButton',
  tag: 'a',
  layout: linkButtonRoot,
  base: base,
  variations: {
    view: {
      css: base$1
    },
    size: {
      css: base$2
    },
    disabled: {
      css: base$3,
      attrs: true
    }
  },
  defaults: {
    view: 'default',
    size: 'm'
  }
};

export { linkButtonConfig, linkButtonRoot };
