import 'core-js/modules/es.symbol.js';
import 'core-js/modules/es.array.filter.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 _extends from '@babel/runtime/helpers/extends';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import * as React from 'react';
import PropTypes from 'prop-types';
import Button from '../Button/Button.js';
import { settings } from '../../constants/Settings.js';
import deprecate from '../../internal/deprecate.js';
import GroupLogic from './GroupLogic.js';
import { GroupLogicPropType } from './RuleBuilderPropTypes.js';
import { Add, TextNewLine } from '@carbon/icons-react';

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: {
    addRule: 'Add rule',
    addGroup: 'Add group'
  },
  // the default logic for the primary rule builder group. Can be ALL or ANY
  groupLogic: 'ALL',
  testId: 'rule-builder-header'
};
var propTypes = {
  id: PropTypes.string.isRequired,
  groupLogic: GroupLogicPropType,
  i18n: PropTypes.shape({
    addRule: PropTypes.string,
    addGroup: PropTypes.string
  }),
  onAddRule: PropTypes.func.isRequired,
  onChange: PropTypes.func.isRequired,
  // TODO: remove the 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."),
  testId: PropTypes.string
};
var RuleBuilderHeader = function RuleBuilderHeader(_ref) {
  var id = _ref.id,
    onAddRule = _ref.onAddRule,
    onChange = _ref.onChange,
    i18n = _ref.i18n,
    groupLogic = _ref.groupLogic,
    testID = _ref.testID,
    testId = _ref.testId;
  var mergedI18n = React.useMemo(function () {
    return _objectSpread(_objectSpread({}, defaultProps.i18n), i18n !== null && i18n !== void 0 ? i18n : {});
  }, [i18n]);
  var handleChangeGroupLogic = React.useCallback(function (_ref2) {
    var selectedItem = _ref2.selectedItem;
    onChange({
      id: id,
      groupLogic: selectedItem.id
    }, true);
  }, [id, onChange]);
  return /*#__PURE__*/React.createElement("div", {
    // TODO: remove the deprecated 'testID' in v3.
    "data-testid": testID || testId,
    className: "".concat(iotPrefix, "--rule-builder-header")
  }, /*#__PURE__*/React.createElement(GroupLogic, {
    id: id,
    selected: groupLogic,
    onChange: handleChangeGroupLogic
  }), /*#__PURE__*/React.createElement("div", {
    className: "".concat(iotPrefix, "--rule-builder-header__buttons")
  }, /*#__PURE__*/React.createElement(Button
  // TODO: remove the deprecated 'testID' in v3.
  , {
    testId: "".concat(testID || testId, "-add-rule-button"),
    kind: "ghost",
    renderIcon: function renderIcon(props) {
      return /*#__PURE__*/React.createElement(Add, _extends({
        size: 32
      }, props));
    },
    onClick: onAddRule()
  }, mergedI18n.addRule), /*#__PURE__*/React.createElement(Button
  // TODO: remove the deprecated 'testID' in v3.
  , {
    testId: "".concat(testID || testId, "-add-group-button"),
    kind: "ghost",
    renderIcon: function renderIcon(props) {
      return /*#__PURE__*/React.createElement(TextNewLine, _extends({
        size: 32
      }, props));
    },
    onClick: onAddRule(undefined, true)
  }, mergedI18n.addGroup)));
};
RuleBuilderHeader.defaultProps = defaultProps;
RuleBuilderHeader.propTypes = propTypes;
RuleBuilderHeader.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "RuleBuilderHeader",
  "props": {
    "i18n": {
      "defaultValue": {
        "value": "{\n  addRule: 'Add rule',\n  addGroup: 'Add group',\n}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "addRule": {
            "name": "string",
            "required": false
          },
          "addGroup": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "groupLogic": {
      "defaultValue": {
        "value": "'ALL'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "custom",
        "raw": "GroupLogicPropType"
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'rule-builder-header'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "id": {
      "description": "",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "onAddRule": {
      "description": "",
      "type": {
        "name": "func"
      },
      "required": true
    },
    "onChange": {
      "description": "",
      "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 RuleBuilderHeader$1 = RuleBuilderHeader;

export { RuleBuilderHeader$1 as default };
