'use strict';

var _extends = require('@babel/runtime/helpers/extends');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
require('core-js/modules/es.array.concat.js');
var React = require('react');
var PropTypes = require('prop-types');
var react = require('@carbon/react');
var classnames = require('classnames');
var Settings = require('../../constants/Settings.js');
var deprecate = require('../../internal/deprecate.js');

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

var _extends__default = /*#__PURE__*/_interopDefault(_extends);
var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties);
var React__default = /*#__PURE__*/_interopDefault(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);

var _excluded = ["children", "loading", "disabled", "className", "onClick", "kind", "recommended", "hasIconOnly", "selected", "testID", "testId"];
var ButtonKinds = ['primary', 'secondary', 'tertiary', 'tertiary--light', 'ghost', 'danger', 'danger--primary', 'danger--ghost', 'danger--tertiary'];
var iotPrefix = Settings.settings.iotPrefix;
var propTypes = {
  /** Show loading spinner, only new prop */
  loading: PropTypes__default.default.bool,
  /** Disable the button will be auto disabled when loading */
  disabled: PropTypes__default.default.bool,
  /** Button label */
  children: PropTypes__default.default.node,
  /** click handler */
  onClick: PropTypes__default.default.func,
  // eslint-disable-line react/require-default-props
  className: PropTypes__default.default.string,
  /** primary, secondary, etc from carbon */
  kind: PropTypes__default.default.oneOf([].concat(ButtonKinds, ['icon-selection'])),
  /** display green border to denote a recommended button to select, to be used with kind: 'icon-selection' */
  recommended: PropTypes__default.default.bool,
  /** Specify if the button is an icon-only button */
  hasIconOnly: PropTypes__default.default.bool,
  /** Toggle selected styling for buttons of kind=icon-selection */
  selected: PropTypes__default.default.bool,
  // TODO: remove deprecated testID prop in v3
  // eslint-disable-next-line react/require-default-props
  testID: deprecate(PropTypes__default.default.string, "The 'testID' prop has been deprecated. Please use 'testId' instead."),
  /** Id that can be used for testing */
  testId: PropTypes__default.default.string
};
var defaultProps = {
  loading: false,
  disabled: false,
  className: null,
  kind: 'primary',
  children: null,
  recommended: false,
  hasIconOnly: false,
  selected: false,
  testId: 'Button'
};
var Button = /*#__PURE__*/React__default.default.forwardRef(function (props, ref) {
  var children = props.children,
    loading = props.loading,
    disabled = props.disabled,
    className = props.className,
    onClick = props.onClick,
    kind = props.kind,
    recommended = props.recommended,
    hasIconOnly = props.hasIconOnly,
    selected = props.selected,
    testID = props.testID,
    testId = props.testId,
    other = _objectWithoutProperties__default.default(props, _excluded);
  return /*#__PURE__*/React__default.default.createElement(react.Button, _extends__default.default({}, other, {
    ref: ref
    // TODO: remove deprecated testID prop in v3
    ,
    "data-testid": testID || testId,
    kind: kind === 'icon-selection' ? 'ghost' : kind,
    hasIconOnly: kind === 'icon-selection' ? true : hasIconOnly,
    onClick: onClick,
    className: classnames__default.default(className, "".concat(iotPrefix, "--btn"), _defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default({}, "".concat(iotPrefix, "--btn-icon-selection"), kind === 'icon-selection'), "".concat(iotPrefix, "--btn-icon-selection--recommended"), kind === 'icon-selection' && !disabled && recommended), "".concat(iotPrefix, "--btn-icon-selection--selected"), kind === 'icon-selection' && selected)),
    disabled: disabled || loading !== undefined && loading !== false
  }), loading ? /*#__PURE__*/React__default.default.createElement(react.Loading, {
    small: true,
    withOverlay: false
  }) : null, kind === 'icon-selection' && !disabled && recommended ? /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(iotPrefix, "--btn-icon-selection--recommended_marker")
  }) : null, children);
});
Button.propTypes = propTypes;
Button.defaultProps = defaultProps;
Button.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "Button",
  "props": {
    "loading": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Show loading spinner, only new prop",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "disabled": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Disable the button will be auto disabled when loading",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "className": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "kind": {
      "defaultValue": {
        "value": "'primary'",
        "computed": false
      },
      "description": "primary, secondary, etc from carbon",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'primary'",
          "computed": false
        }, {
          "value": "'secondary'",
          "computed": false
        }, {
          "value": "'tertiary'",
          "computed": false
        }, {
          "value": "'tertiary--light'",
          "computed": false
        }, {
          "value": "'ghost'",
          "computed": false
        }, {
          "value": "'danger'",
          "computed": false
        }, {
          "value": "'danger--primary'",
          "computed": false
        }, {
          "value": "'danger--ghost'",
          "computed": false
        }, {
          "value": "'danger--tertiary'",
          "computed": false
        }, {
          "value": "'icon-selection'",
          "computed": false
        }]
      },
      "required": false
    },
    "children": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Button label",
      "type": {
        "name": "node"
      },
      "required": false
    },
    "recommended": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "display green border to denote a recommended button to select, to be used with kind: 'icon-selection'",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "hasIconOnly": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Specify if the button is an icon-only button",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "selected": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Toggle selected styling for buttons of kind=icon-selection",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'Button'",
        "computed": false
      },
      "description": "Id that can be used for testing",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "onClick": {
      "description": "click handler",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "testID": {
      "description": "",
      "type": {
        "name": "custom",
        "raw": "deprecate(\n  PropTypes.string,\n  `The 'testID' prop has been deprecated. Please use 'testId' instead.`\n)"
      },
      "required": false
    }
  }
};
var Button$1 = Button;

module.exports = Button$1;
