'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

require('core-js/modules/es.symbol.js');
require('core-js/modules/es.array.filter.js');
require('core-js/modules/es.object.get-own-property-descriptor.js');
require('core-js/modules/es.object.get-own-property-descriptors.js');
require('core-js/modules/es.object.keys.js');
require('core-js/modules/es.object.to-string.js');
require('core-js/modules/web.dom-collections.for-each.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var React = require('react');
var PropTypes = require('prop-types');
var iconsReact = require('@carbon/icons-react');
var editorUtils = require('../../../../DashboardEditor/editorUtils.js');
var ContentFormItemTitle = require('../ContentFormItemTitle.js');
var Button = require('../../../../Button/Button.js');
var List = require('../../../../List/List.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var React__default = /*#__PURE__*/_interopDefault(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);

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__default.default(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__default.default.shape({}).isRequired,
  /** Hierarchy Data items to display */
  hierarchyDataItemListItems: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({})),
  /** Handler for hierarchy data item changes */
  handleHierarchyDataItemChange: PropTypes__default.default.func.isRequired,
  /** Class name for the list */
  listClassName: PropTypes__default.default.string,
  i18n: PropTypes__default.default.shape({
    hierarchyDataItemSectionTitle: PropTypes__default.default.string,
    addHierarchyDataItemLabel: PropTypes__default.default.string
  }),
  actions: editorUtils.defaultDashboardEditorActionsProps
};
var defaultProps = {
  hierarchyDataItemListItems: [],
  listClassName: '',
  i18n: {
    hierarchyDataItemSectionTitle: 'Hierarchy Data Item',
    addHierarchyDataItemLabel: 'Add Hierarchy Data Item'
  },
  actions: editorUtils.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 = React.useMemo(function () {
    return hasHierarchyDataItemsEnabled && hasHierarchyDataItemsEnabled(cardConfig);
  }, [cardConfig, hasHierarchyDataItemsEnabled]);
  return isHierarchyDataItemsEnabled && /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, /*#__PURE__*/React__default.default.createElement(ContentFormItemTitle, {
    title: mergedI18n.hierarchyDataItemSectionTitle
  }), /*#__PURE__*/React__default.default.createElement(Button, {
    kind: "ghost",
    renderIcon: iconsReact.Add,
    size: "md",
    onClick: function onClick() {
      return onAddHierarchyDataItems(cardConfig, handleHierarchyDataItemChange);
    }
  }, mergedI18n.addHierarchyDataItemLabel), /*#__PURE__*/React__default.default.createElement(List.default, {
    className: listClassName
    // need to force an empty "empty state"
    ,
    emptyState: /*#__PURE__*/React__default.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;

exports.default = HierarchyDataFormItems$1;
exports.isHierarchyDataItem = isHierarchyDataItem;
