'use strict';

var React = require('react');
var PropTypes = require('prop-types');
var Settings = require('../../constants/Settings.js');
var Button = require('../Button/Button.js');

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

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

var iotPrefix = Settings.settings.iotPrefix;
var propTypes = {
  /**
   * The label on a single menu button
   */
  label: PropTypes__default.default.string,
  /**
   * These are passed from the MenuButton to open to the menu.
   */
  onSecondaryActionClick: PropTypes__default.default.func,
  onPrimaryActionClick: PropTypes__default.default.func,
  /**
   * Optional prop to change the closed state icon on the button
   * Can be a React component class
   */
  renderIcon: PropTypes__default.default.oneOfType([PropTypes__default.default.func, PropTypes__default.default.object]).isRequired,
  /**
   * If specifying the `renderIcon` prop, provide a description for that icon that can
   * be read by screen readers
   */
  iconDescription: PropTypes__default.default.string.isRequired,
  testId: PropTypes__default.default.string.isRequired,
  /**
   * The size of the button and the dropdown items
   */
  size: PropTypes__default.default.oneOf(['sm', 'md', 'default']).isRequired,
  /**
   * The kind of button to render
   */
  kind: PropTypes__default.default.oneOf(['primary', 'secondary', 'tertiary', 'ghost']).isRequired
};
var defaultProps = {
  label: '',
  onSecondaryActionClick: null,
  onPrimaryActionClick: null
};
var SingleMenuButton = /*#__PURE__*/React__default.default.forwardRef(function (_ref, ref) {
  var onSecondaryActionClick = _ref.onSecondaryActionClick,
    onPrimaryActionClick = _ref.onPrimaryActionClick,
    label = _ref.label,
    iconDescription = _ref.iconDescription,
    renderIcon = _ref.renderIcon,
    testId = _ref.testId,
    size = _ref.size,
    kind = _ref.kind;
  return /*#__PURE__*/React__default.default.createElement(Button, {
    ref: ref,
    className: "".concat(iotPrefix, "--menu-button__trigger"),
    onClick: label ? onPrimaryActionClick : onSecondaryActionClick,
    iconDescription: iconDescription,
    renderIcon: renderIcon,
    hasIconOnly: !label,
    kind: kind,
    testId: label ? "".concat(testId, "-single") : "".concat(testId, "-icon"),
    size: size
  }, label);
});
SingleMenuButton.propTypes = propTypes;
SingleMenuButton.defaultProps = defaultProps;
SingleMenuButton.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "SingleMenuButton",
  "props": {
    "label": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "The label on a single menu button",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "onSecondaryActionClick": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "These are passed from the MenuButton to open to the menu.",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "onPrimaryActionClick": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "renderIcon": {
      "description": "Optional prop to change the closed state icon on the button\nCan be a React component class",
      "type": {
        "name": "union",
        "value": [{
          "name": "func"
        }, {
          "name": "object"
        }]
      },
      "required": true
    },
    "iconDescription": {
      "description": "If specifying the `renderIcon` prop, provide a description for that icon that can\nbe read by screen readers",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "testId": {
      "description": "",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "size": {
      "description": "The size of the button and the dropdown items",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'sm'",
          "computed": false
        }, {
          "value": "'md'",
          "computed": false
        }, {
          "value": "'default'",
          "computed": false
        }]
      },
      "required": true
    },
    "kind": {
      "description": "The kind of button to render",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'primary'",
          "computed": false
        }, {
          "value": "'secondary'",
          "computed": false
        }, {
          "value": "'tertiary'",
          "computed": false
        }, {
          "value": "'ghost'",
          "computed": false
        }]
      },
      "required": true
    }
  }
};

exports.SingleMenuButton = SingleMenuButton;
