import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { getSecureRelForTarget } from '../../services';
import { SoftIcon } from "../Icon";
import { TYPES as ICON_TYPES } from "../Icon/SoftIcon";
import { SoftLoadingSpinner } from "../Loading";
const colorToClassNameMap = {
    primary: 'softButton--primary',
    secondary: 'softButton--secondary',
    warning: 'softButton--warning',
    danger: 'softButton--danger',
    ghost: 'softButton--ghost',
    text: 'softButton--text',
};
export const COLORS = Object.keys(colorToClassNameMap);
const sizeToClassNameMap = {
    s: 'softButton--small',
    m: null,
    l: 'softButton--large',
};
export const SIZES = Object.keys(sizeToClassNameMap);
const iconSideToClassNameMap = {
    left: null,
    right: 'softButton--iconRight',
};
export const ICON_SIDES = Object.keys(iconSideToClassNameMap);
export const SoftButton = ({ children, className, iconType, iconSide, color, size, fill, isDisabled, isLoading, href, target, rel, type, buttonRef, contentProps, textProps, fullWidth, ...rest }) => {
    // If in the loading state, force disabled to true
    isDisabled = isLoading ? true : isDisabled;
    const classes = classNames('softButton', colorToClassNameMap[color], sizeToClassNameMap[size], iconSideToClassNameMap[iconSide], className, {
        'softButton--fill': fill,
        'softButton--fullWidth': fullWidth,
    });
    const contentClassNames = classNames('softButton__content', contentProps && contentProps.className);
    const textClassNames = classNames('softButton__text', textProps && textProps.className);
    let buttonIcon;
    if (isLoading) {
        buttonIcon = (React.createElement(SoftLoadingSpinner, { className: "euiButton__spinner", size: "m" }));
    }
    else if (iconType) {
        buttonIcon = (React.createElement(SoftIcon, { className: "SoftButton__icon", type: iconType, size: "m", "aria-hidden": "true" }));
    }
    const innerNode = (React.createElement("span", Object.assign({}, contentProps, { className: contentClassNames }),
        buttonIcon,
        React.createElement("span", Object.assign({}, textProps, { className: textClassNames }), children)));
    // <a> elements don't respect the `disabled` attribute. So if we're disabled, we'll just pretend
    // this is a button and piggyback off its disabled styles.
    if (href && !isDisabled) {
        const secureRel = getSecureRelForTarget({ href, target, rel });
        return (React.createElement("a", Object.assign({ className: classes, href: href, target: target, rel: secureRel, ref: buttonRef }, rest), innerNode));
    }
    else {
        return (React.createElement("button", Object.assign({ disabled: isDisabled, className: classes, type: type, ref: buttonRef }, rest), innerNode));
    }
};
// @ts-ignore
SoftButton.defaultProps = {
    size: 'm',
    type: 'button',
    iconSide: 'left',
    color: 'primary',
    fill: false,
};
// @ts-ignore
SoftButton.propTypes = {
    children: PropTypes.node,
    className: PropTypes.string,
    /**
     * See EuiIcon
     */
    iconType: PropTypes.oneOf(ICON_TYPES),
    iconSide: PropTypes.oneOf(ICON_SIDES),
    /**
     * Add more focus to an action
     */
    fill: PropTypes.bool,
    /**
     * Define the color of the button
     */
    color: PropTypes.oneOf(COLORS),
    size: PropTypes.oneOf(SIZES),
    /**
     * Expands button to fill the width of the parent
     */
    fullWidth: PropTypes.bool,
    isDisabled: PropTypes.bool,
    href: PropTypes.string,
    target: PropTypes.string,
    rel: PropTypes.string,
    onClick: PropTypes.func,
    /**
     * Adds/swaps for loading spinner & disables
     */
    isLoading: PropTypes.bool,
    /**
     * Standard HTML attribute
     */
    type: PropTypes.string,
    buttonRef: PropTypes.func,
    /**
     * Passes props to `euiButton__content` span
     */
    contentProps: PropTypes.object,
    /**
     * Passes props to `euiButton__text` span
     */
    textProps: PropTypes.object,
};
//# sourceMappingURL=SoftButton.js.map