import _extends from '@babel/runtime/helpers/extends';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import 'core-js/modules/es.function.name.js';
import 'core-js/modules/es.object.values.js';
import PropTypes from 'prop-types';
import React__default from 'react';
import classnames from 'classnames';
import { Button } from '@carbon/react';
import { settings } from '../../constants/Settings.js';

var _excluded = ["className", "index", "name", "renderIcon", "onClick", "onKeyDown", "selected", "size", "text", "testId", "children", "disabled"];
var prefix = settings.prefix,
  iotPrefix = settings.iotPrefix;
var ICON_SWITCH_SIZES = {
  small: 'sm',
  default: 'md',
  large: 'lg'
};
var IconSwitch = /*#__PURE__*/React__default.forwardRef(function (props, ref) {
  var className = props.className,
    index = props.index,
    name = props.name,
    renderIcon = props.renderIcon,
    onClick = props.onClick,
    onKeyDown = props.onKeyDown,
    selected = props.selected;
    props.size;
    var text = props.text,
    testId = props.testId,
    children = props.children,
    disabled = props.disabled,
    other = _objectWithoutProperties(props, _excluded);
  var handleClick = function handleClick(e) {
    e.preventDefault();
    onClick({
      index: index,
      name: name,
      text: text
    });
  };
  var handleKeyDown = function handleKeyDown(e) {
    var key = e.key || e.which;
    if (key === 'Enter' || key === 13 || key === ' ' || key === 32) {
      onKeyDown({
        index: index,
        name: name,
        text: text
      });
    }
  };
  var classes = classnames(className, "".concat(prefix, "--content-switcher-btn"), // Class from carbon
  "".concat(iotPrefix, "--icon-switch"), _defineProperty({}, "".concat(prefix, "--content-switcher--selected"), selected));
  var iconButtonClasses = classnames("".concat(prefix, "--content-switcher-popover__wrapper"), // Class from carbon
  _defineProperty(_defineProperty({}, "".concat(prefix, "--content-switcher-popover--selected"), selected), "".concat(prefix, "--content-switcher-popover--disabled"), disabled));
  var commonProps = {
    onClick: handleClick,
    onKeyDown: handleKeyDown,
    className: classes,
    disabled: disabled
  };
  return /*#__PURE__*/React__default.createElement(Button, _extends({
    ref: ref,
    renderIcon: renderIcon,
    iconDescription: text,
    kind: "secondary",
    hasIconOnly: true,
    tooltipPosition: "top",
    "data-testid": testId,
    wrapperClasses: iconButtonClasses
  }, other, commonProps), children);
});
IconSwitch.propTypes = {
  /**
   * Specify an optional className to be added to your Switch
   */
  className: PropTypes.string,
  /**
   * The index of your Switch in your ContentSwitcher that is used for event handlers.
   * Reserved for usage in ContentSwitcher
   */
  index: PropTypes.number.isRequired,
  /**
   * Provide the name of your Switch that is used for event handlers
   */
  name: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  /**
   * A handler that is invoked when a user clicks on the control.
   * Reserved for usage in ContentSwitcher
   */
  onClick: PropTypes.func,
  /**
   * A handler that is invoked on the key down event for the control.
   * Reserved for usage in ContentSwitcher
   */
  onKeyDown: PropTypes.func,
  /**
   * Whether your Switch is selected. Reserved for usage in ContentSwitcher
   */
  selected: PropTypes.bool,
  /**
   * The tooltip text which will display when hovering over the switch
   */
  text: PropTypes.string.isRequired,
  /**
   * @deprecated The `size` prop for `IconSwitch` has been deprecated. This should now be set using the `size` prop
   * in the ContentSwitcher component. The options are 'sm', 'md', 'lg'.
   */
  size: PropTypes.oneOf(Object.values(ICON_SWITCH_SIZES)),
  /**
   * Define the icon render to be rendered.
   * Can be a React component class
   */
  renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).isRequired,
  testId: PropTypes.string,
  /** The button should be disabled */
  disabled: PropTypes.bool,
  children: PropTypes.node
};
IconSwitch.defaultProps = {
  className: undefined,
  selected: false,
  name: '',
  size: 'sm',
  onClick: undefined,
  onKeyDown: undefined,
  testId: 'icon-switch',
  disabled: false,
  children: undefined
};
IconSwitch.displayName = 'IconSwitch';
IconSwitch.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "IconSwitch",
  "props": {
    "className": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "Specify an optional className to be added to your Switch",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "selected": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Whether your Switch is selected. Reserved for usage in ContentSwitcher",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "name": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "Provide the name of your Switch that is used for event handlers",
      "type": {
        "name": "union",
        "value": [{
          "name": "string"
        }, {
          "name": "number"
        }]
      },
      "required": false
    },
    "size": {
      "defaultValue": {
        "value": "'sm'",
        "computed": false
      },
      "description": "@deprecated The `size` prop for `IconSwitch` has been deprecated. This should now be set using the `size` prop\nin the ContentSwitcher component. The options are 'sm', 'md', 'lg'.",
      "type": {
        "name": "enum",
        "value": [{
          "value": "\"md\"",
          "computed": false
        }, {
          "value": "\"lg\"",
          "computed": false
        }, {
          "value": "\"sm\"",
          "computed": false
        }]
      },
      "required": false
    },
    "onClick": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "A handler that is invoked when a user clicks on the control.\nReserved for usage in ContentSwitcher",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "onKeyDown": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "A handler that is invoked on the key down event for the control.\nReserved for usage in ContentSwitcher",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'icon-switch'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "disabled": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "The button should be disabled",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "children": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "",
      "type": {
        "name": "node"
      },
      "required": false
    },
    "index": {
      "description": "The index of your Switch in your ContentSwitcher that is used for event handlers.\nReserved for usage in ContentSwitcher",
      "type": {
        "name": "number"
      },
      "required": true
    },
    "text": {
      "description": "The tooltip text which will display when hovering over the switch",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "renderIcon": {
      "description": "Define the icon render to be rendered.\nCan be a React component class",
      "type": {
        "name": "union",
        "value": [{
          "name": "func"
        }, {
          "name": "object"
        }]
      },
      "required": true
    }
  }
};
var IconSwitch$1 = IconSwitch;

export { ICON_SWITCH_SIZES, IconSwitch$1 as default };
