import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _omit from '../../../../../node_modules/lodash-es/omit.js';
import isEmpty from '../../../../../node_modules/lodash-es/isEmpty.js';
import _regeneratorRuntime from '@babel/runtime/regenerator';
import 'core-js/modules/es.array.concat.js';
import 'core-js/modules/es.array.filter.js';
import 'core-js/modules/es.array.find.js';
import 'core-js/modules/es.array.includes.js';
import 'core-js/modules/es.array.map.js';
import 'core-js/modules/es.symbol.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/es.string.includes.js';
import 'core-js/modules/web.dom-collections.for-each.js';
import React__default, { useState, useMemo, useCallback } from 'react';
import PropTypes from 'prop-types';
import { v4 } from 'uuid';
import hash from 'object-hash';
import { ComboBox, MultiSelect } from '@carbon/react';
import { settings } from '../../../../../constants/Settings.js';
import { DataItemsPropTypes, DashboardEditorActionsPropTypes, handleDataSeriesChange, dimensionFilterFunction, defaultDashboardEditorActionsProps } from '../../../../DashboardEditor/editorUtils.js';
import Button from '../../../../Button/Button.js';
import List from '../../../../List/List.js';
import DataSeriesFormItemModal from '../DataSeriesFormItemModal.js';
import ContentFormItemTitle from '../ContentFormItemTitle.js';
import { CARD_SIZES, CARD_TYPES } from '../../../../../constants/LayoutConstants.js';
import { formatDataItemsForDropdown } from '../DataSeriesFormItems/DataSeriesFormContent.js';
import HierarchyDataFormItems, { isHierarchyDataItem } from '../HierarchyDataFormItems/HierarchyDataFormItems.js';
import { Edit, MisuseOutline } from '@carbon/icons-react';

var _excluded = ["thresholds"];
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 propTypes = {
  cardConfig: PropTypes.shape({
    id: PropTypes.string,
    title: PropTypes.string,
    size: PropTypes.oneOf(Object.keys(CARD_SIZES)),
    type: PropTypes.oneOf([CARD_TYPES.TABLE]),
    content: PropTypes.shape({
      columns: PropTypes.arrayOf(PropTypes.shape({
        label: PropTypes.string,
        dataSourceId: PropTypes.string,
        type: PropTypes.string,
        dataItemType: PropTypes.string
      })),
      thresholds: PropTypes.arrayOf(PropTypes.shape({
        color: PropTypes.string,
        comparison: PropTypes.string,
        dataSourceId: PropTypes.string,
        icon: PropTypes.string,
        value: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.bool])
      }))
    }),
    dataSource: PropTypes.shape({
      groupBy: PropTypes.arrayOf(PropTypes.string)
    })
  }),
  /* callback when any changes are made to the card config, the full updated card JSON is passed as the argument */
  onChange: PropTypes.func.isRequired,
  i18n: PropTypes.shape({
    dataItemEditorTitle: PropTypes.string,
    dataItemEditorDataItemTitle: PropTypes.string,
    dataItemEditorDimensionTitle: PropTypes.string,
    dataItemEditorDataItemLabel: PropTypes.string,
    dataItemEditorLegendColor: PropTypes.string,
    tableColumnEditorSectionTitle: PropTypes.string,
    dataItemEditorSectionTableTooltipText: PropTypes.string,
    dataSeriesTitle: PropTypes.string,
    selectDataItems: PropTypes.string,
    selectGroupByDimensions: PropTypes.string,
    dataItem: PropTypes.string,
    edit: PropTypes.string,
    remove: PropTypes.string,
    customize: PropTypes.string
  }),
  /** an array of dataItems to be included on each card */
  dataItems: DataItemsPropTypes,
  /** if provided, returns an array of strings which are the dataItems to be allowed
   * on each card
   * getValidDataItems(card, selectedTimeRange)
   */
  getValidDataItems: PropTypes.func,
  /** an object where the keys are available dimensions and the values are the values available for those dimensions
   *  ex: { manufacturer: ['Rentech', 'GHI Industries'], deviceid: ['73000', '73001', '73002'] }
   */
  availableDimensions: PropTypes.shape({}),
  selectedTimeRange: PropTypes.string.isRequired,
  /** list of dataItem names that have been selected to display on the card */
  selectedDataItems: PropTypes.arrayOf(PropTypes.string),
  /** the callback is called with a list of the new data item names selected */
  setSelectedDataItems: PropTypes.func.isRequired,
  /** optional link href's for each card type that will appear in a tooltip */
  dataSeriesItemLinks: PropTypes.shape({
    table: PropTypes.string
  }),
  translateWithId: PropTypes.func.isRequired,
  actions: DashboardEditorActionsPropTypes
};
var defaultProps = {
  cardConfig: {},
  i18n: {
    dataItemEditorTitle: 'Edit data series',
    dataItemEditorDataItemTitle: 'Data item',
    dataItemEditorDimensionTitle: 'Group by',
    dataItemEditorDataItemLabel: 'Label',
    dataItemEditorLegendColor: 'Legend color',
    tableColumnEditorSectionTitle: 'Columns',
    dataItemEditorSectionTableTooltipText: 'Display metrics in columns. Filter the metrics by dimensions or device ID from Group by.',
    selectDataItems: 'Select data item(s)',
    selectGroupByDimensions: 'Select dimension(s)',
    dataItem: 'Data item',
    edit: 'Edit',
    remove: 'Remove',
    filter: 'Filter',
    customize: 'Customize'
  },
  dataItems: [],
  getValidDataItems: null,
  selectedDataItems: [],
  availableDimensions: {},
  dataSeriesItemLinks: null,
  actions: defaultDashboardEditorActionsProps
};
var TableCardFormContent = function TableCardFormContent(_ref) {
  var cardConfig = _ref.cardConfig,
    dataItems = _ref.dataItems,
    getValidDataItems = _ref.getValidDataItems,
    _onChange = _ref.onChange,
    selectedTimeRange = _ref.selectedTimeRange,
    selectedDataItems = _ref.selectedDataItems,
    setSelectedDataItems = _ref.setSelectedDataItems,
    availableDimensions = _ref.availableDimensions,
    i18n = _ref.i18n,
    dataSeriesItemLinks = _ref.dataSeriesItemLinks,
    translateWithId = _ref.translateWithId,
    actions = _ref.actions;
  var onEditDataItem = actions.onEditDataItem;
  var mergedI18n = _objectSpread(_objectSpread({}, defaultProps.i18n), i18n);
  var _cardConfig$content = cardConfig.content,
    columns = _cardConfig$content.columns,
    thresholds = _cardConfig$content.thresholds;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    showEditor = _useState2[0],
    setShowEditor = _useState2[1];
  // Need to keep track of the data item that's currently being edited so the detailed modal knows which one to show
  var _useState3 = useState({}),
    _useState4 = _slicedToArray(_useState3, 2),
    editDataItem = _useState4[0],
    setEditDataItem = _useState4[1];

  // Initialize the selected columns if its not currently set
  var dataSection = useMemo(function () {
    var a = Array.isArray(columns) ? columns.map(function (column) {
      var filteredThresholds = (thresholds === null || thresholds === void 0 ? void 0 : thresholds.filter(function (threshold) {
        return column.dataSourceId === threshold.dataSourceId;
      })) || [];
      return _objectSpread(_objectSpread({}, column), !isEmpty(filteredThresholds) // only set thresholds if they exist
      ? {
        thresholds: filteredThresholds
      } : {});
    }) : [];
    return a;
  }, [columns, thresholds]);
  var baseClassName = "".concat(iotPrefix, "--card-edit-form");

  // find valid dimension data item names
  var validDimensions = useMemo(function () {
    return Object.keys(availableDimensions).map(function (i) {
      return {
        id: i,
        text: i
      };
    });
  }, [availableDimensions]);
  var initialSelectedDimensions = useMemo(function () {
    var _cardConfig$dataSourc, _cardConfig$dataSourc2;
    return (_cardConfig$dataSourc = cardConfig === null || cardConfig === void 0 || (_cardConfig$dataSourc2 = cardConfig.dataSource) === null || _cardConfig$dataSourc2 === void 0 || (_cardConfig$dataSourc2 = _cardConfig$dataSourc2.groupBy) === null || _cardConfig$dataSourc2 === void 0 ? void 0 : _cardConfig$dataSourc2.map(function (dataSourceId) {
      return {
        id: dataSourceId,
        text: dataSourceId
      };
    })) !== null && _cardConfig$dataSourc !== void 0 ? _cardConfig$dataSourc : [];
  }, [cardConfig]);
  var validDataItems = getValidDataItems ? getValidDataItems(cardConfig, selectedTimeRange) : dataItems;
  var handleOnDataSeriesChange = function handleOnDataSeriesChange(_ref2) {
    var selectedItem = _ref2.selectedItem;
    // ignore the extra value added by the "enter" keypress
    if (selectedItem && !isEmpty(selectedItem.id)) {
      var itemWithMetaData = validDataItems === null || validDataItems === void 0 ? void 0 : validDataItems.find(function (_ref3) {
        var dataItemId = _ref3.dataItemId;
        return dataItemId === selectedItem.id;
      });
      var selectedItems = [].concat(_toConsumableArray(dataSection), [_objectSpread(_objectSpread({}, itemWithMetaData && _objectSpread({}, itemWithMetaData)), {}, {
        // create a unique dataSourceId if it's going into the attributes section
        // if it's going into the groupBy section, then just use the dataItemId
        dataSourceId: (itemWithMetaData === null || itemWithMetaData === void 0 ? void 0 : itemWithMetaData.destination) === 'groupBy' ? selectedItem.id : "".concat(selectedItem.id, "_").concat(v4())
      })]);
      var newCard = handleDataSeriesChange(selectedItems, cardConfig, null, null);
      setSelectedDataItems(selectedItems.map(function (_ref4) {
        var text = _ref4.text;
        return text;
      }));
      _onChange(newCard);
    }
  };
  var handleHierarchyDataItemChange = useCallback(function (items) {
    var updatedItems = items.map(function (item) {
      return _objectSpread(_objectSpread({}, item), {}, {
        // create a unique dataSourceId if it's going into attributes
        // if it's going into the groupBy section then just use the dataItem ID
        dataSourceId: "".concat(item.dataItemId, "_").concat(v4())
      });
    });
    var selectedItems = [].concat(_toConsumableArray(dataSection), _toConsumableArray(updatedItems));
    var newCard = handleDataSeriesChange(selectedItems, cardConfig, null, null);
    setSelectedDataItems(selectedItems.map(function (_ref5) {
      var text = _ref5.text;
      return text;
    }));
    _onChange(newCard);
  }, [cardConfig, dataSection, _onChange, setSelectedDataItems]);

  // need to handle thresholds from the DataSeriesFormItemModal and convert it to the right format
  var handleDataItemModalChanges = useCallback(function (card) {
    var _card$content, _thresholds$filter, _card$content2;
    // Get datasource from columns with thresholds
    var columnThresholdDataSource = (card === null || card === void 0 || (_card$content = card.content) === null || _card$content === void 0 || (_card$content = _card$content.columns) === null || _card$content === void 0 || (_card$content = _card$content.filter(function (column) {
      var _column$thresholds;
      return column === null || column === void 0 || (_column$thresholds = column.thresholds) === null || _column$thresholds === void 0 ? void 0 : _column$thresholds.length;
    })) === null || _card$content === void 0 ? void 0 : _card$content.map(function (column) {
      return column.dataSourceId;
    })) || [];

    // Consider existing thresholds outside columns and filter existing thresholds from edited column
    var allThresholds = isEmpty(columnThresholdDataSource) ? [] : (thresholds === null || thresholds === void 0 || (_thresholds$filter = thresholds.filter(function (_ref6) {
      var dataSourceId = _ref6.dataSourceId;
      return !columnThresholdDataSource.includes(dataSourceId);
    })) === null || _thresholds$filter === void 0 ? void 0 : _thresholds$filter.map(function (threshold) {
      return _objectSpread({}, threshold);
    })) || [];

    // the table card is looking for the thresholds on the main content object
    var updatedColumns = card === null || card === void 0 || (_card$content2 = card.content) === null || _card$content2 === void 0 || (_card$content2 = _card$content2.columns) === null || _card$content2 === void 0 ? void 0 : _card$content2.map(
    // eslint-disable-next-line no-unused-vars
    function (_ref7) {
      var columnThresholds = _ref7.thresholds,
        others = _objectWithoutProperties(_ref7, _excluded);
      if (!isEmpty(columnThresholds)) {
        allThresholds.push.apply(allThresholds, _toConsumableArray(columnThresholds.map(function (threshold) {
          return _objectSpread(_objectSpread({}, threshold), {}, {
            dataSourceId: others === null || others === void 0 ? void 0 : others.dataSourceId
          });
        })));
      }
      return others;
    });
    _onChange(_objectSpread(_objectSpread({}, card), {}, {
      content: _objectSpread(_objectSpread({}, _omit(card.content, 'thresholds')), {}, {
        columns: updatedColumns
      }, !isEmpty(allThresholds) ? {
        thresholds: allThresholds
      } : {})
    }));
  }, [_onChange, thresholds]);
  var handleRemoveButton = useCallback(function (dataItem) {
    var _cardConfig$content2, _cardConfig$dataSourc3;
    var filteredColumns = dataSection.filter(function (item) {
      return item.dataSourceId !== dataItem.dataSourceId;
    });
    // Filter existing thresholds
    var filteredThresholds = cardConfig === null || cardConfig === void 0 || (_cardConfig$content2 = cardConfig.content) === null || _cardConfig$content2 === void 0 || (_cardConfig$content2 = _cardConfig$content2.thresholds) === null || _cardConfig$content2 === void 0 ? void 0 : _cardConfig$content2.filter(function (item) {
      return item.dataSourceId !== dataItem.dataSourceId;
    });
    // Need to determine whether we should remove these from the groupBy section
    var filteredGroupBy = cardConfig === null || cardConfig === void 0 || (_cardConfig$dataSourc3 = cardConfig.dataSource) === null || _cardConfig$dataSourc3 === void 0 || (_cardConfig$dataSourc3 = _cardConfig$dataSourc3.groupBy) === null || _cardConfig$dataSourc3 === void 0 ? void 0 : _cardConfig$dataSourc3.filter(function (groupByItem) {
      return groupByItem !== dataItem.dataSourceId;
    });
    setSelectedDataItems(filteredColumns.map(function (item) {
      return item.dataSourceId;
    }));

    // if we no longer have a groupBy, then we can exclude the dataSource from the response
    var updatedDataSource = {};
    if (!isEmpty(filteredGroupBy)) {
      updatedDataSource = {
        dataSource: _objectSpread(_objectSpread({}, cardConfig.dataSource), {}, {
          groupBy: filteredGroupBy
        })
      };
    } else if (cardConfig.dataSource) {
      updatedDataSource = {
        dataSource: _objectSpread({}, _omit(cardConfig.dataSource, 'groupBy'))
      };
    }
    var updatedContent = _objectSpread(_objectSpread({}, cardConfig.content), {}, {
      columns: filteredColumns,
      thresholds: filteredThresholds
    });

    /* istanbul ignore else */
    if (isEmpty(filteredThresholds)) {
      delete updatedContent.thresholds;
    }
    _onChange(_objectSpread(_objectSpread({}, cardConfig), {}, {
      content: updatedContent
    }, updatedDataSource));
  }, [cardConfig, dataSection, _onChange, setSelectedDataItems]);
  var handleEditButton = useCallback(/*#__PURE__*/function () {
    var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dataItem) {
      var dataItemWithMetaData, aggregationMethods;
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            dataItemWithMetaData = validDataItems === null || validDataItems === void 0 ? void 0 : validDataItems.find(function (_ref9) {
              var dataItemId = _ref9.dataItemId;
              return dataItemId === dataItem.dataItemId;
            }); // Call back function for on click of edit button
            /* istanbul ignore else */
            if (!onEditDataItem) {
              _context.next = 6;
              break;
            }
            _context.next = 4;
            return onEditDataItem(cardConfig, dataItem, dataItemWithMetaData);
          case 4:
            aggregationMethods = _context.sent;
            if (dataItemWithMetaData && !isEmpty(aggregationMethods)) {
              dataItemWithMetaData.aggregationMethods = aggregationMethods;
            }
          case 6:
            // need to reset the card to include the latest dataSection
            setEditDataItem(_objectSpread(_objectSpread({}, dataItemWithMetaData), dataItem));
            setShowEditor(true);
          case 8:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function (_x) {
      return _ref8.apply(this, arguments);
    };
  }(), [cardConfig, onEditDataItem, validDataItems]);
  var generateListItems = useCallback(function (data) {
    var _data$filter;
    var isHierarchy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
    return data === null || data === void 0 || (_data$filter = data.filter(function (dataItem) {
      return isHierarchyDataItem(dataItem) === isHierarchy;
    })) === null || _data$filter === void 0 ? void 0 : _data$filter.map(function (dataItem) {
      return {
        id: dataItem.dataSourceId,
        content: {
          value: dataItem.label || dataItem.dataItemId,
          icon: null,
          rowActions: function rowActions() {
            return [/*#__PURE__*/React__default.createElement(Button, {
              key: "data-item-".concat(dataItem.dataSourceId),
              renderIcon: Edit,
              hasIconOnly: true,
              kind: "ghost",
              size: "sm",
              onClick: function onClick() {
                return handleEditButton(dataItem);
              },
              iconDescription: mergedI18n.edit,
              tooltipPosition: "left",
              tooltipAlignment: "center"
            }), /*#__PURE__*/React__default.createElement(Button, {
              key: "data-item-".concat(dataItem.dataSourceId, "_remove"),
              renderIcon: MisuseOutline,
              hasIconOnly: true,
              kind: "ghost",
              size: "sm",
              onClick: function onClick() {
                return handleRemoveButton(dataItem);
              },
              iconDescription: mergedI18n.remove,
              tooltipPosition: "left",
              tooltipAlignment: "center"
            })];
          }
        }
      };
    });
  }, [handleEditButton, handleRemoveButton, mergedI18n.edit, mergedI18n.remove]);
  var dataListItems = useMemo(function () {
    return generateListItems(dataSection);
  }, [dataSection, generateListItems]);
  var hierarchyDataListItems = useMemo(function () {
    return generateListItems(dataSection, true);
  }, [dataSection, generateListItems]);
  return /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(iotPrefix, "--table-card-form--content")
  }, /*#__PURE__*/React__default.createElement(DataSeriesFormItemModal, {
    cardConfig: cardConfig,
    showEditor: showEditor,
    setShowEditor: setShowEditor,
    editDataSeries: dataSection,
    editDataItem: editDataItem,
    setEditDataItem: setEditDataItem,
    availableDimensions: availableDimensions,
    onChange: handleDataItemModalChanges,
    i18n: mergedI18n,
    actions: actions,
    options: {
      hasColorDropdown: false,
      hasUnit: false,
      hasDecimalPlacesDropdown: false,
      hasThresholds: true,
      hasTooltip: true
    },
    isLarge: true
  }), /*#__PURE__*/React__default.createElement(ContentFormItemTitle, {
    title: mergedI18n.tableColumnEditorSectionTitle,
    tooltip: _objectSpread({
      tooltipText: mergedI18n.dataItemEditorSectionTableTooltipText
    }, dataSeriesItemLinks !== null && dataSeriesItemLinks !== void 0 && dataSeriesItemLinks.table ? {
      linkText: mergedI18n.dataItemEditorSectionTooltipLinkText,
      href: dataSeriesItemLinks.table
    } : {})
  }), /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(baseClassName, "--input") // data item selector
  }, /*#__PURE__*/React__default.createElement(ComboBox
  // need to re-gen if selected card changes or if a dataItem is removed from the list
  , {
    key: "data-item-select-".concat(hash(validDataItems), "-selected_card-id-").concat(cardConfig.id),
    id: "".concat(cardConfig.id, "_dataSourceIds-combobox"),
    items: formatDataItemsForDropdown(validDataItems),
    itemToString: function itemToString(item) {
      return item === null || item === void 0 ? void 0 : item.text;
    },
    titleText: mergedI18n.dataItem,
    addToList: false,
    placeholder: mergedI18n.filter,
    translateWithId: translateWithId,
    shouldFilterItem: function shouldFilterItem(_ref10) {
      var _item$text;
      var item = _ref10.item,
        inputValue = _ref10.inputValue;
      return isEmpty(inputValue) || (item === null || item === void 0 || (_item$text = item.text) === null || _item$text === void 0 || (_item$text = _item$text.toLowerCase()) === null || _item$text === void 0 ? void 0 : _item$text.includes(inputValue === null || inputValue === void 0 ? void 0 : inputValue.toLowerCase()));
    }
    // clears out the input field after each selection
    ,
    selectedItem: {
      id: '',
      text: ''
    },
    onChange: handleOnDataSeriesChange,
    light: true
  })), !isEmpty(validDimensions) && /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(baseClassName, "--input") // Dimensions selector
  }, /*#__PURE__*/React__default.createElement(MultiSelect
  // need to re-gen if selected card changes or if a dataItem is removed from the list
  , {
    key: "data-item-select-selected_card-id-".concat(cardConfig.id),
    id: "".concat(cardConfig.id, "_dataSourceIds"),
    label: mergedI18n.selectGroupByDimensions,
    translateWithId: translateWithId,
    direction: "bottom",
    itemToString: function itemToString(item) {
      return item.id;
    },
    selectedItems: initialSelectedDimensions,
    items: validDimensions,
    light: true,
    onChange: function onChange(_ref11) {
      var selectedItems = _ref11.selectedItems;
      var existingDimensionColumns = dataSection.filter(dimensionFilterFunction);
      if (existingDimensionColumns.length > selectedItems.length) {
        var _existingDimensionCol;
        var selectedDimensions = selectedItems.map(function (dimension) {
          return dimension.text;
        });
        handleRemoveButton((_existingDimensionCol = existingDimensionColumns.find(function (dimension) {
          return !selectedDimensions.includes(dimension.dataSourceId);
        })) !== null && _existingDimensionCol !== void 0 ? _existingDimensionCol : {});
      } else {
        // Add the new dimensions as dimension columns at the beginning of the table
        var newCard = handleDataSeriesChange(selectedItems.map(function (i) {
          return {
            dataItemId: i.id,
            dataSourceId: i.id,
            label: i.text,
            dataItemType: 'DIMENSION',
            destination: 'groupBy'
          };
        }), cardConfig, null, null);
        _onChange(newCard);
      }
    },
    titleText: mergedI18n.dataItemEditorDimensionTitle
  })), /*#__PURE__*/React__default.createElement(List
  // Lists the selected dataItem columns in the bottom section and allow additional configuration
  , {
    key: "data-item-list".concat(selectedDataItems.length)
    // need to force an empty "empty state"
    ,
    emptyState: /*#__PURE__*/React__default.createElement("div", null),
    title: "",
    items: dataListItems
  }), /*#__PURE__*/React__default.createElement(HierarchyDataFormItems, {
    cardConfig: cardConfig,
    hierarchyDataItemListItems: hierarchyDataListItems,
    handleHierarchyDataItemChange: handleHierarchyDataItemChange,
    i18n: i18n,
    actions: actions
  }));
};
TableCardFormContent.defaultProps = defaultProps;
TableCardFormContent.propTypes = propTypes;
TableCardFormContent.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "TableCardFormContent",
  "props": {
    "cardConfig": {
      "defaultValue": {
        "value": "{}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "id": {
            "name": "string",
            "required": false
          },
          "title": {
            "name": "string",
            "required": false
          },
          "size": {
            "name": "enum",
            "computed": true,
            "value": "Object.keys(CARD_SIZES)",
            "required": false
          },
          "type": {
            "name": "enum",
            "value": [{
              "value": "CARD_TYPES.TABLE",
              "computed": true
            }],
            "required": false
          },
          "content": {
            "name": "shape",
            "value": {
              "columns": {
                "name": "arrayOf",
                "value": {
                  "name": "shape",
                  "value": {
                    "label": {
                      "name": "string",
                      "required": false
                    },
                    "dataSourceId": {
                      "name": "string",
                      "required": false
                    },
                    "type": {
                      "name": "string",
                      "required": false
                    },
                    "dataItemType": {
                      "name": "string",
                      "required": false
                    }
                  }
                },
                "required": false
              },
              "thresholds": {
                "name": "arrayOf",
                "value": {
                  "name": "shape",
                  "value": {
                    "color": {
                      "name": "string",
                      "required": false
                    },
                    "comparison": {
                      "name": "string",
                      "required": false
                    },
                    "dataSourceId": {
                      "name": "string",
                      "required": false
                    },
                    "icon": {
                      "name": "string",
                      "required": false
                    },
                    "value": {
                      "name": "union",
                      "value": [{
                        "name": "number"
                      }, {
                        "name": "string"
                      }, {
                        "name": "bool"
                      }],
                      "required": false
                    }
                  }
                },
                "required": false
              }
            },
            "required": false
          },
          "dataSource": {
            "name": "shape",
            "value": {
              "groupBy": {
                "name": "arrayOf",
                "value": {
                  "name": "string"
                },
                "required": false
              }
            },
            "required": false
          }
        }
      },
      "required": false
    },
    "i18n": {
      "defaultValue": {
        "value": "{\n  dataItemEditorTitle: 'Edit data series',\n  dataItemEditorDataItemTitle: 'Data item',\n  dataItemEditorDimensionTitle: 'Group by',\n  dataItemEditorDataItemLabel: 'Label',\n  dataItemEditorLegendColor: 'Legend color',\n  tableColumnEditorSectionTitle: 'Columns',\n  dataItemEditorSectionTableTooltipText:\n    'Display metrics in columns. Filter the metrics by dimensions or device ID from Group by.',\n  selectDataItems: 'Select data item(s)',\n  selectGroupByDimensions: 'Select dimension(s)',\n  dataItem: 'Data item',\n  edit: 'Edit',\n  remove: 'Remove',\n  filter: 'Filter',\n  customize: 'Customize',\n}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "dataItemEditorTitle": {
            "name": "string",
            "required": false
          },
          "dataItemEditorDataItemTitle": {
            "name": "string",
            "required": false
          },
          "dataItemEditorDimensionTitle": {
            "name": "string",
            "required": false
          },
          "dataItemEditorDataItemLabel": {
            "name": "string",
            "required": false
          },
          "dataItemEditorLegendColor": {
            "name": "string",
            "required": false
          },
          "tableColumnEditorSectionTitle": {
            "name": "string",
            "required": false
          },
          "dataItemEditorSectionTableTooltipText": {
            "name": "string",
            "required": false
          },
          "dataSeriesTitle": {
            "name": "string",
            "required": false
          },
          "selectDataItems": {
            "name": "string",
            "required": false
          },
          "selectGroupByDimensions": {
            "name": "string",
            "required": false
          },
          "dataItem": {
            "name": "string",
            "required": false
          },
          "edit": {
            "name": "string",
            "required": false
          },
          "remove": {
            "name": "string",
            "required": false
          },
          "customize": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "dataItems": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "an array of dataItems to be included on each card",
      "type": {
        "name": "custom",
        "raw": "DataItemsPropTypes"
      },
      "required": false
    },
    "getValidDataItems": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "if provided, returns an array of strings which are the dataItems to be allowed\non each card\ngetValidDataItems(card, selectedTimeRange)",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "selectedDataItems": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "list of dataItem names that have been selected to display on the card",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "string"
        }
      },
      "required": false
    },
    "availableDimensions": {
      "defaultValue": {
        "value": "{}",
        "computed": false
      },
      "description": "an object where the keys are available dimensions and the values are the values available for those dimensions\n ex: { manufacturer: ['Rentech', 'GHI Industries'], deviceid: ['73000', '73001', '73002'] }",
      "type": {
        "name": "shape",
        "value": {}
      },
      "required": false
    },
    "dataSeriesItemLinks": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "optional link href's for each card type that will appear in a tooltip",
      "type": {
        "name": "shape",
        "value": {
          "table": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "actions": {
      "defaultValue": {
        "value": "defaultDashboardEditorActionsProps",
        "computed": true
      },
      "description": "",
      "type": {
        "name": "custom",
        "raw": "DashboardEditorActionsPropTypes"
      },
      "required": false
    },
    "onChange": {
      "description": "",
      "type": {
        "name": "func"
      },
      "required": true
    },
    "selectedTimeRange": {
      "description": "",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "setSelectedDataItems": {
      "description": "the callback is called with a list of the new data item names selected",
      "type": {
        "name": "func"
      },
      "required": true
    },
    "translateWithId": {
      "description": "",
      "type": {
        "name": "func"
      },
      "required": true
    }
  }
};
var TableCardFormContent$1 = TableCardFormContent;

export { TableCardFormContent$1 as default };
