import _defineProperty from '@babel/runtime/helpers/defineProperty';
import 'core-js/modules/es.symbol.js';
import 'core-js/modules/es.array.filter.js';
import 'core-js/modules/es.array.find.js';
import 'core-js/modules/es.function.name.js';
import 'core-js/modules/es.object.get-own-property-descriptor.js';
import 'core-js/modules/es.object.get-own-property-descriptors.js';
import 'core-js/modules/es.object.keys.js';
import 'core-js/modules/es.object.to-string.js';
import 'core-js/modules/web.dom-collections.for-each.js';
import { Dropdown } from '@carbon/react';
import * as React from 'react';
import PropTypes from 'prop-types';
import { settings } from '../../constants/Settings.js';

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var iotPrefix = settings.iotPrefix;
var defaultProps = {
  i18n: {
    all: 'ALL',
    any: 'ANY',
    areTrueStatement: ' of the following are true'
  },
  selected: undefined,
  onChange: function onChange() {}
};
var propTypes = {
  id: PropTypes.string.isRequired,
  i18n: PropTypes.shape({
    all: PropTypes.string,
    any: PropTypes.string,
    areTrueStatement: PropTypes.string
  }),
  selected: PropTypes.string,
  onChange: PropTypes.func
};
var GroupLogic = function GroupLogic(_ref) {
  var id = _ref.id,
    i18n = _ref.i18n,
    selected = _ref.selected,
    onChange = _ref.onChange;
  var mergedI18n = React.useMemo(function () {
    return _objectSpread(_objectSpread({}, defaultProps.i18n), i18n !== null && i18n !== void 0 ? i18n : {});
  }, [i18n]);
  var groupLogic = React.useMemo(function () {
    return [{
      id: 'ALL',
      name: mergedI18n.all
    }, {
      id: 'ANY',
      name: mergedI18n.any
    }];
  }, [mergedI18n.all, mergedI18n.any]);
  var initialSelectedItem = React.useMemo(function () {
    var found = groupLogic.find(function (_ref2) {
      var logicId = _ref2.id;
      return logicId === selected;
    });
    if (found) {
      return found;
    }
    return groupLogic && groupLogic[0];
  }, [groupLogic, selected]);
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
    className: "".concat(iotPrefix, "--rule-builder-header__dropdown")
  }, /*#__PURE__*/React.createElement(Dropdown, {
    id: id,
    light: true,
    itemToString: function itemToString(item) {
      return item.name;
    },
    items: groupLogic,
    label: initialSelectedItem.name,
    initialSelectedItem: initialSelectedItem,
    onChange: onChange,
    "data-testid": "".concat(id, "-group-logic-dropdown")
  })), /*#__PURE__*/React.createElement("span", null, mergedI18n.areTrueStatement));
};
GroupLogic.defaultProps = defaultProps;
GroupLogic.propTypes = propTypes;
GroupLogic.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "GroupLogic",
  "props": {
    "i18n": {
      "defaultValue": {
        "value": "{\n  all: 'ALL',\n  any: 'ANY',\n  areTrueStatement: ' of the following are true',\n}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "all": {
            "name": "string",
            "required": false
          },
          "any": {
            "name": "string",
            "required": false
          },
          "areTrueStatement": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "selected": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "onChange": {
      "defaultValue": {
        "value": "() => {}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "id": {
      "description": "",
      "type": {
        "name": "string"
      },
      "required": true
    }
  }
};
var GroupLogic$1 = GroupLogic;

export { GroupLogic$1 as default };
