import _extends from '@babel/runtime/helpers/extends';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import React__default from 'react';
import PropTypes from 'prop-types';
import { settings } from '../../constants/Settings.js';
import { Dropdown as Dropdown$2 } from '@carbon/react';

var _excluded = ["itemToString", "testId"];
var iotPrefix = settings.iotPrefix;
var propTypes = {
  /**
   * 'aria-label' of the ListBox component.
   */
  ariaLabel: PropTypes.string,
  /**
   * Provide a custom className to be applied on the bx--dropdown node
   */
  className: PropTypes.string,
  /**
   * Specify the direction of the dropdown. Can be either top or bottom.
   */
  direction: PropTypes.oneOf(['top', 'bottom']),
  /**
   * Disable the control
   */
  disabled: PropTypes.bool,
  /**
   * Additional props passed to Downshift
   */
  // eslint-disable-next-line react/forbid-prop-types
  downshiftProps: PropTypes.object,
  /**
   * Provide helper text that is used alongside the control label for
   * additional help
   */
  helperText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
  /**
   * Specify a custom `id`
   */
  id: PropTypes.string.isRequired,
  /**
   * Allow users to pass in an arbitrary item or a string (in case their items are an array of strings)
   * from their collection that are pre-selected
   */
  initialSelectedItem: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
  /**
   * Specify if the currently selected value is invalid.
   */
  invalid: PropTypes.bool,
  /**
   * Message which is displayed if the value is invalid.
   */
  invalidText: PropTypes.string,
  /**
   * Function to render items as custom components instead of strings.
   * Defaults to null and is overriden by a getter
   */
  itemToElement: PropTypes.func,
  /**
   * Helper function passed to downshift that allows the library to render a
   * given item to a string label. By default, it extracts the `label` field
   * from a given item to serve as the item label in the list.
   */
  itemToString: PropTypes.func,
  /**
   * We try to stay as generic as possible here to allow individuals to pass
   * in a collection of whatever kind of data structure they prefer
   */
  // eslint-disable-next-line react/forbid-prop-types
  items: PropTypes.array.isRequired,
  /**
   * Generic `label` that will be used as the textual representation of what
   * this field is for
   */
  label: PropTypes.node.isRequired,
  /**
   * `true` to use the light version.
   */
  light: PropTypes.bool,
  /**
   * `onChange` is a utility for this controlled component to communicate to a
   * consuming component what kind of internal state changes are occuring.
   */
  onChange: PropTypes.func,
  /**
   * In the case you want to control the dropdown selection entirely.
   */
  selectedItem: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
  /**
   * Specify the size of the ListBox. Currently supports either `sm`, or `xl` as an option.
   */
  size: PropTypes.oneOf(['sm', 'xl']),
  /**
   * Provide the title text that will be read by a screen reader when
   * visiting this control
   */
  titleText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
  /**
   * Callback function for translating ListBoxMenuIcon SVG title
   */
  translateWithId: PropTypes.func,
  /**
   * The dropdown type, `default` or `inline`
   */
  type: PropTypes.oneOf(['default', 'inline']),
  testId: PropTypes.string
};
var defaultPropTypes = {
  ariaLabel: undefined,
  className: undefined,
  downshiftProps: undefined,
  initialSelectedItem: null,
  invalid: false,
  invalidText: '',
  onChange: null,
  selectedItem: undefined,
  disabled: false,
  size: undefined,
  translateWithId: function translateWithId() {},
  type: 'default',
  itemToString: null,
  itemToElement: null,
  light: false,
  titleText: '',
  helperText: '',
  direction: 'bottom',
  testId: 'dropdown'
};
var defaultItemToString = function defaultItemToString(item) {
  var content;
  if (typeof item === 'string') {
    content = item;
  } else if (item !== null && item !== void 0 && item.icon) {
    content = /*#__PURE__*/React__default.createElement("div", {
      className: "".concat(iotPrefix, "--dropdown__item"),
      title: item.text
    }, /*#__PURE__*/React__default.createElement("div", {
      className: "".concat(iotPrefix, "--dropdown__label")
    }, /*#__PURE__*/React__default.createElement(item === null || item === void 0 ? void 0 : item.icon), /*#__PURE__*/React__default.createElement("div", {
      className: "".concat(iotPrefix, "--dropdown__label__content")
    }, item.text)));
  } else {
    content = item ? item.text : '';
  }
  return content;
};
var Dropdown = function Dropdown(_ref) {
  var itemToString = _ref.itemToString,
    testId = _ref.testId,
    other = _objectWithoutProperties(_ref, _excluded);
  return /*#__PURE__*/React__default.createElement(Dropdown$2, _extends({
    "data-testid": testId
  }, other, {
    className: "".concat(iotPrefix, "--dropdown"),
    itemToString: itemToString !== null ? itemToString : defaultItemToString
  }));
};
Dropdown.propTypes = propTypes;
Dropdown.defaultProps = defaultPropTypes;
Dropdown.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "Dropdown",
  "props": {
    "ariaLabel": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "'aria-label' of the ListBox component.",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "className": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "Provide a custom className to be applied on the bx--dropdown node",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "downshiftProps": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "Additional props passed to Downshift",
      "type": {
        "name": "object"
      },
      "required": false
    },
    "initialSelectedItem": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Allow users to pass in an arbitrary item or a string (in case their items are an array of strings)\nfrom their collection that are pre-selected",
      "type": {
        "name": "union",
        "value": [{
          "name": "object"
        }, {
          "name": "string"
        }]
      },
      "required": false
    },
    "invalid": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Specify if the currently selected value is invalid.",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "invalidText": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "Message which is displayed if the value is invalid.",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "onChange": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "`onChange` is a utility for this controlled component to communicate to a\nconsuming component what kind of internal state changes are occuring.",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "selectedItem": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "In the case you want to control the dropdown selection entirely.",
      "type": {
        "name": "union",
        "value": [{
          "name": "object"
        }, {
          "name": "string"
        }]
      },
      "required": false
    },
    "disabled": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Disable the control",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "size": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "Specify the size of the ListBox. Currently supports either `sm`, or `xl` as an option.",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'sm'",
          "computed": false
        }, {
          "value": "'xl'",
          "computed": false
        }]
      },
      "required": false
    },
    "translateWithId": {
      "defaultValue": {
        "value": "() => {}",
        "computed": false
      },
      "description": "Callback function for translating ListBoxMenuIcon SVG title",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "type": {
      "defaultValue": {
        "value": "'default'",
        "computed": false
      },
      "description": "The dropdown type, `default` or `inline`",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'default'",
          "computed": false
        }, {
          "value": "'inline'",
          "computed": false
        }]
      },
      "required": false
    },
    "itemToString": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Helper function passed to downshift that allows the library to render a\ngiven item to a string label. By default, it extracts the `label` field\nfrom a given item to serve as the item label in the list.",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "itemToElement": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Function to render items as custom components instead of strings.\nDefaults to null and is overriden by a getter",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "light": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "`true` to use the light version.",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "titleText": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "Provide the title text that will be read by a screen reader when\nvisiting this control",
      "type": {
        "name": "union",
        "value": [{
          "name": "string"
        }, {
          "name": "node"
        }]
      },
      "required": false
    },
    "helperText": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "Provide helper text that is used alongside the control label for\nadditional help",
      "type": {
        "name": "union",
        "value": [{
          "name": "string"
        }, {
          "name": "node"
        }]
      },
      "required": false
    },
    "direction": {
      "defaultValue": {
        "value": "'bottom'",
        "computed": false
      },
      "description": "Specify the direction of the dropdown. Can be either top or bottom.",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'top'",
          "computed": false
        }, {
          "value": "'bottom'",
          "computed": false
        }]
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'dropdown'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "id": {
      "description": "Specify a custom `id`",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "items": {
      "description": "We try to stay as generic as possible here to allow individuals to pass\nin a collection of whatever kind of data structure they prefer",
      "type": {
        "name": "array"
      },
      "required": true
    },
    "label": {
      "description": "Generic `label` that will be used as the textual representation of what\nthis field is for",
      "type": {
        "name": "node"
      },
      "required": true
    }
  }
};
var Dropdown$1 = Dropdown;

export { Dropdown$1 as default };
