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 _defineProperty from '@babel/runtime/helpers/defineProperty';
import React__default, { useMemo } from 'react';
import PropTypes from 'prop-types';
import { Add } from '@carbon/icons-react';
import { defaultDashboardEditorActionsProps } from '../../../../DashboardEditor/editorUtils.js';
import ContentFormItemTitle from '../ContentFormItemTitle.js';
import Button from '../../../../Button/Button.js';
import List from '../../../../List/List.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 isHierarchyDataItem = function isHierarchyDataItem(dataItem) {
  return dataItem.hasOwnProperty('resourceData');
};
var propTypes = {
  cardConfig: PropTypes.shape({}).isRequired,
  /** Hierarchy Data items to display */
  hierarchyDataItemListItems: PropTypes.arrayOf(PropTypes.shape({})),
  /** Handler for hierarchy data item changes */
  handleHierarchyDataItemChange: PropTypes.func.isRequired,
  /** Class name for the list */
  listClassName: PropTypes.string,
  i18n: PropTypes.shape({
    hierarchyDataItemSectionTitle: PropTypes.string,
    addHierarchyDataItemLabel: PropTypes.string
  }),
  actions: defaultDashboardEditorActionsProps
};
var defaultProps = {
  hierarchyDataItemListItems: [],
  listClassName: '',
  i18n: {
    hierarchyDataItemSectionTitle: 'Hierarchy Data Item',
    addHierarchyDataItemLabel: 'Add Hierarchy Data Item'
  },
  actions: defaultDashboardEditorActionsProps
};
var HierarchyDataFormItems = function HierarchyDataFormItems(_ref) {
  var cardConfig = _ref.cardConfig,
    hierarchyDataItemListItems = _ref.hierarchyDataItemListItems,
    handleHierarchyDataItemChange = _ref.handleHierarchyDataItemChange,
    listClassName = _ref.listClassName,
    i18n = _ref.i18n,
    actions = _ref.actions;
  var mergedI18n = _objectSpread(_objectSpread({}, defaultProps.i18n), i18n);
  var onAddHierarchyDataItems = actions.onAddHierarchyDataItems,
    hasHierarchyDataItemsEnabled = actions.dataSeriesFormActions.hasHierarchyDataItemsEnabled;

  // determine if hierarchy data items are available
  var isHierarchyDataItemsEnabled = useMemo(function () {
    return hasHierarchyDataItemsEnabled && hasHierarchyDataItemsEnabled(cardConfig);
  }, [cardConfig, hasHierarchyDataItemsEnabled]);
  return isHierarchyDataItemsEnabled && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(ContentFormItemTitle, {
    title: mergedI18n.hierarchyDataItemSectionTitle
  }), /*#__PURE__*/React__default.createElement(Button, {
    kind: "ghost",
    renderIcon: Add,
    size: "md",
    onClick: function onClick() {
      return onAddHierarchyDataItems(cardConfig, handleHierarchyDataItemChange);
    }
  }, mergedI18n.addHierarchyDataItemLabel), /*#__PURE__*/React__default.createElement(List, {
    className: listClassName
    // need to force an empty "empty state"
    ,
    emptyState: /*#__PURE__*/React__default.createElement("div", null),
    title: "",
    items: hierarchyDataItemListItems
  }));
};
HierarchyDataFormItems.propTypes = propTypes;
HierarchyDataFormItems.defaultProps = defaultProps;
HierarchyDataFormItems.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "HierarchyDataFormItems",
  "props": {
    "hierarchyDataItemListItems": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "Hierarchy Data items to display",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": {}
        }
      },
      "required": false
    },
    "listClassName": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "Class name for the list",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "i18n": {
      "defaultValue": {
        "value": "{\n  hierarchyDataItemSectionTitle: 'Hierarchy Data Item',\n  addHierarchyDataItemLabel: 'Add Hierarchy Data Item',\n}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "hierarchyDataItemSectionTitle": {
            "name": "string",
            "required": false
          },
          "addHierarchyDataItemLabel": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "actions": {
      "defaultValue": {
        "value": "defaultDashboardEditorActionsProps",
        "computed": true
      },
      "description": "",
      "type": {
        "name": "custom",
        "raw": "defaultDashboardEditorActionsProps"
      },
      "required": false
    },
    "cardConfig": {
      "description": "",
      "type": {
        "name": "shape",
        "value": {}
      },
      "required": true
    },
    "handleHierarchyDataItemChange": {
      "description": "Handler for hierarchy data item changes",
      "type": {
        "name": "func"
      },
      "required": true
    }
  }
};
var HierarchyDataFormItems$1 = HierarchyDataFormItems;

export { HierarchyDataFormItems$1 as default, isHierarchyDataItem };
