import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import 'core-js/modules/es.function.name.js';
import React__default, { useState } from 'react';
import PropTypes from 'prop-types';
import { Dropdown } from '@carbon/react';
import { purple70, cyan50, teal70, magenta70, red50, red90, green60, blue80, magenta50, purple50, teal50, cyan90 } from '@carbon/colors';
import warning from 'warning';
import { settings } from '../../constants/Settings.js';
import deprecate from '../../internal/deprecate.js';

var iotPrefix = settings.iotPrefix;
var colorPropType = PropTypes.shape({
  carbonColor: PropTypes.string,
  name: PropTypes.string
});
var propTypes = {
  /** Array of colors to be shown */
  colors: PropTypes.arrayOf(colorPropType),
  /** True disables the control */
  disabled: PropTypes.bool,
  /** The label of the Dropdown, defaults to 'Select a color' */
  label: PropTypes.string,
  /** True if the dropdown should hide the color names that display next to the color box */
  hideLabels: PropTypes.bool,
  /** The title of the Dropdown, defaults to 'Color' */
  titleText: PropTypes.string,
  /** Required Id string */
  id: PropTypes.string.isRequired,
  /** True if the light theme is to be used, defaults to false */
  light: PropTypes.bool,
  /** Callback for when any of the Dropdown color value changes */
  onChange: PropTypes.func.isRequired,
  /** Callback to translate common strings */
  translateWithId: PropTypes.func,
  /** The selected color, use to set initial color */
  selectedColor: colorPropType,
  // TODO: remove deprecated testID in v3.
  // eslint-disable-next-line react/require-default-props
  testID: deprecate(PropTypes.string, "The 'testID' prop has been deprecated. Please use 'testId' instead."),
  /** Id used if needed for testing */
  testId: PropTypes.string
};
var defaultProps = {
  colors: [{
    carbonColor: purple70,
    name: 'purple70'
  }, {
    carbonColor: cyan50,
    name: 'cyan50'
  }, {
    carbonColor: teal70,
    name: 'teal70'
  }, {
    carbonColor: magenta70,
    name: 'magenta70'
  }, {
    carbonColor: red50,
    name: 'red50'
  }, {
    carbonColor: red90,
    name: 'red90'
  }, {
    carbonColor: green60,
    name: 'green60'
  }, {
    carbonColor: blue80,
    name: 'blue80'
  }, {
    carbonColor: magenta50,
    name: 'magenta50'
  }, {
    carbonColor: purple50,
    name: 'purple50'
  }, {
    carbonColor: teal50,
    name: 'teal50'
  }, {
    carbonColor: cyan90,
    name: 'cyan90'
  }],
  disabled: false,
  label: 'Select a color',
  hideLabels: false,
  light: false,
  selectedColor: undefined,
  testId: 'color-dropdown',
  titleText: 'Color',
  translateWithId: undefined
};
var ColorDropdown = function ColorDropdown(_ref) {
  var colors = _ref.colors,
    disabled = _ref.disabled,
    id = _ref.id,
    label = _ref.label,
    hideLabels = _ref.hideLabels,
    light = _ref.light,
    _onChange = _ref.onChange,
    selectedColorProp = _ref.selectedColor,
    titleText = _ref.titleText,
    testID = _ref.testID,
    testId = _ref.testId,
    translateWithId = _ref.translateWithId;
  React__default.useEffect(function () {
    {
      warning(false, 'The `ColorDropdown` is an experimental component and could be lacking unit test and documentation. Be aware that minor version bumps could introduce breaking changes. For the reasons listed above use of this component in production is highly discouraged') ;
    }
  }, []);
  var _useState = useState(selectedColorProp),
    _useState2 = _slicedToArray(_useState, 2),
    selectedColor = _useState2[0],
    setSelectedColor = _useState2[1];
  var renderColorItem = function renderColorItem(item) {
    return /*#__PURE__*/React__default.createElement("div", {
      title: "".concat(item.name),
      className: "".concat(iotPrefix, "--color-dropdown__item")
    }, /*#__PURE__*/React__default.createElement("div", {
      className: "".concat(iotPrefix, "--color-dropdown__item-border")
    }, /*#__PURE__*/React__default.createElement("div", {
      title: "".concat(item.carbonColor),
      className: "".concat(iotPrefix, "--color-dropdown__color-sample"),
      style: {
        backgroundColor: item.carbonColor
      }
    }), !hideLabels && /*#__PURE__*/React__default.createElement("div", {
      className: "".concat(iotPrefix, "--color-dropdown__color-name")
    }, item.name)));
  };
  return /*#__PURE__*/React__default.createElement(Dropdown, {
    className: "".concat(iotPrefix, "--color-dropdown"),
    id: id,
    itemToElement: renderColorItem,
    itemToString: function itemToString(item) {
      return item.name;
    },
    items: colors,
    label: label,
    light: light,
    title: label,
    translateWithId: translateWithId,
    onChange: function onChange(_ref2) {
      var selectedItem = _ref2.selectedItem;
      setSelectedColor(selectedItem);
      _onChange({
        color: selectedItem
      });
    },
    selectedItem: selectedColor,
    renderSelectedItem: renderColorItem,
    titleText: titleText,
    type: "default",
    "data-testid": testID || testId,
    disabled: disabled,
    autoAlign: true
  });
};
ColorDropdown.propTypes = propTypes;
ColorDropdown.defaultProps = defaultProps;
ColorDropdown.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "ColorDropdown",
  "props": {
    "colors": {
      "defaultValue": {
        "value": "[\n  { carbonColor: purple70, name: 'purple70' },\n  { carbonColor: cyan50, name: 'cyan50' },\n  { carbonColor: teal70, name: 'teal70' },\n  { carbonColor: magenta70, name: 'magenta70' },\n  { carbonColor: red50, name: 'red50' },\n  { carbonColor: red90, name: 'red90' },\n  { carbonColor: green60, name: 'green60' },\n  { carbonColor: blue80, name: 'blue80' },\n  { carbonColor: magenta50, name: 'magenta50' },\n  { carbonColor: purple50, name: 'purple50' },\n  { carbonColor: teal50, name: 'teal50' },\n  { carbonColor: cyan90, name: 'cyan90' },\n]",
        "computed": false
      },
      "description": "Array of colors to be shown",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "custom",
          "raw": "colorPropType"
        }
      },
      "required": false
    },
    "disabled": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "True disables the control",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "label": {
      "defaultValue": {
        "value": "'Select a color'",
        "computed": false
      },
      "description": "The label of the Dropdown, defaults to 'Select a color'",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "hideLabels": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "True if the dropdown should hide the color names that display next to the color box",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "light": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "True if the light theme is to be used, defaults to false",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "selectedColor": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "The selected color, use to set initial color",
      "type": {
        "name": "custom",
        "raw": "colorPropType"
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'color-dropdown'",
        "computed": false
      },
      "description": "Id used if needed for testing",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "titleText": {
      "defaultValue": {
        "value": "'Color'",
        "computed": false
      },
      "description": "The title of the Dropdown, defaults to 'Color'",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "translateWithId": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "Callback to translate common strings",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "id": {
      "description": "Required Id string",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "onChange": {
      "description": "Callback for when any of the Dropdown color value changes",
      "type": {
        "name": "func"
      },
      "required": true
    },
    "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 ColorDropdown$1 = ColorDropdown;

export { ColorDropdown$1 as default };
