'use strict';

var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var omit = require('../../../../node_modules/lodash-es/omit.js');
var isEmpty = require('../../../../node_modules/lodash-es/isEmpty.js');
require('core-js/modules/es.symbol.js');
require('core-js/modules/es.array.concat.js');
require('core-js/modules/es.array.filter.js');
require('core-js/modules/es.array.find.js');
require('core-js/modules/es.array.find-index.js');
require('core-js/modules/es.array.map.js');
require('core-js/modules/es.array.slice.js');
require('core-js/modules/es.array.sort.js');
require('core-js/modules/es.number.constructor.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/es.regexp.to-string.js');
require('core-js/modules/web.dom-collections.for-each.js');
var React = require('react');
var PropTypes = require('prop-types');
var colors = require('@carbon/colors');
var react = require('@carbon/react');
var Settings = require('../../../../constants/Settings.js');
var editorUtils = require('../../../DashboardEditor/editorUtils.js');
var ColorDropdown = require('../../../ColorDropdown/ColorDropdown.js');
var LayoutConstants = require('../../../../constants/LayoutConstants.js');
var cardUtilityFunctions = require('../../../../utils/cardUtilityFunctions.js');
var ThresholdsFormItem = require('./ThresholdsFormItem.js');
var ComposedModal = require('../../../ComposedModal/ComposedModal.js');
var iconsReact = require('@carbon/icons-react');

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

var _toConsumableArray__default = /*#__PURE__*/_interopDefault(_toConsumableArray);
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 iotPrefix = Settings.settings.iotPrefix,
  prefix = Settings.settings.prefix;
var propTypes = {
  /* card value */
  cardConfig: PropTypes__default.default.shape({
    id: PropTypes__default.default.string,
    title: PropTypes__default.default.string,
    size: PropTypes__default.default.string,
    type: PropTypes__default.default.string,
    content: PropTypes__default.default.shape({
      series: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
        label: PropTypes__default.default.string,
        dataSourceId: PropTypes__default.default.string,
        color: PropTypes__default.default.string
      })),
      columns: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
        dataSourceId: PropTypes__default.default.string,
        label: PropTypes__default.default.string,
        type: PropTypes__default.default.string,
        dataItemType: PropTypes__default.default.string
      })),
      type: PropTypes__default.default.string,
      xLabel: PropTypes__default.default.string,
      yLabel: PropTypes__default.default.string,
      unit: PropTypes__default.default.string,
      includeZeroOnXaxis: PropTypes__default.default.bool,
      includeZeroOnYaxis: PropTypes__default.default.bool,
      timeDataSourceId: PropTypes__default.default.string
    }),
    interval: PropTypes__default.default.string,
    showLegend: PropTypes__default.default.bool
  }),
  showEditor: PropTypes__default.default.bool,
  setShowEditor: PropTypes__default.default.func,
  editDataItem: PropTypes__default.default.shape({
    columnType: PropTypes__default.default.oneOf(['LITERAL', 'BOOLEAN', 'TIMESTAMP', 'NUMBER']),
    dataSourceId: PropTypes__default.default.string,
    dataFilter: PropTypes__default.default.objectOf(PropTypes__default.default.string),
    /** Maps to data item columnType */
    type: PropTypes__default.default.string,
    /** Maps to data item type */
    dataItemType: PropTypes__default.default.string,
    aggregationMethods: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
      id: PropTypes__default.default.string,
      text: PropTypes__default.default.string
    })),
    aggregationMethod: PropTypes__default.default.string,
    grain: PropTypes__default.default.string,
    label: PropTypes__default.default.string,
    dataItemId: PropTypes__default.default.string,
    color: PropTypes__default.default.string,
    unit: PropTypes__default.default.string,
    precision: PropTypes__default.default.number,
    thresholds: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
      color: PropTypes__default.default.string,
      comparison: PropTypes__default.default.stirng,
      icon: PropTypes__default.default.string,
      value: PropTypes__default.default.oneOfType([PropTypes__default.default.bool, PropTypes__default.default.number, PropTypes__default.default.string])
    })),
    tooltip: PropTypes__default.default.string
  }),
  setEditDataItem: PropTypes__default.default.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__default.default.shape({}),
  onChange: PropTypes__default.default.func.isRequired,
  editDataSeries: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
    dataSourceId: PropTypes__default.default.string,
    label: PropTypes__default.default.string,
    color: PropTypes__default.default.string
  })),
  validDataItems: editorUtils.DataItemsPropTypes,
  isSummaryDashboard: PropTypes__default.default.bool,
  isLarge: PropTypes__default.default.bool,
  i18n: PropTypes__default.default.shape({
    dataItemEditorDataItemTitle: PropTypes__default.default.string,
    dataItemEditorDataItemLabel: PropTypes__default.default.string,
    dataItemEditorLegendColor: PropTypes__default.default.string,
    dataItemEditorSectionTitle: PropTypes__default.default.string,
    selectDataItems: PropTypes__default.default.string,
    dataItem: PropTypes__default.default.string,
    edit: PropTypes__default.default.string,
    dataItemEditorDataItemCustomLabel: PropTypes__default.default.string,
    /** Function receiving the dataItemSource & dataItemId as params:
     * (dataItemSource, dataItemId) => `${dataItemSource}: ${dataItemId}` */
    dataItemEditorDataItemHelperText: PropTypes__default.default.func,
    dataItemEditorDataItemUnit: PropTypes__default.default.string,
    dataItemEditorDataItemFilter: PropTypes__default.default.string,
    dataItemEditorDataItemThresholds: PropTypes__default.default.string,
    dataItemEditorDataItemAddThreshold: PropTypes__default.default.string,
    source: PropTypes__default.default.string,
    primaryButtonLabelText: PropTypes__default.default.string,
    secondaryButtonLabelText: PropTypes__default.default.string
  }),
  /** whether to use translated labels in cards */
  shouldUseTranslatedLabels: PropTypes__default.default.bool,
  actions: editorUtils.DashboardEditorActionsPropTypes,
  /**
   * Used to override the default behaviour of handleDataItemEdit. if we dont pass any function then it uses handleDefaultDataItemEdit function by default
   */
  handleDataItemEdit: PropTypes__default.default.func,
  options: PropTypes__default.default.shape({
    hasColorDropdown: PropTypes__default.default.bool,
    hasUnit: PropTypes__default.default.bool,
    hasDecimalPlacesDropdown: PropTypes__default.default.bool,
    hasThresholds: PropTypes__default.default.bool,
    hasTooltip: PropTypes__default.default.bool
  })
};
var defaultProps = {
  cardConfig: {},
  i18n: {
    dataItemEditorDataSeriesTitle: 'Customize data series',
    dataItemEditorValueCardTitle: 'Edit data',
    dataItemEditorDataItemLabel: 'Label',
    dataItemEditorLegendColor: 'Legend color',
    dataItemEditorSectionTitle: 'Data series',
    selectDataItems: 'Select data items',
    dataItem: 'Data item',
    edit: 'Edit',
    example: 'Example',
    notSet: 'Not set',
    none: 'None',
    dataItemEditorDataItemCustomLabel: 'Custom label',
    dataItemEditorDataItemHelperText: function dataItemEditorDataItemHelperText(dataItemSource, dataItemId) {
      return "".concat(dataItemSource, ": ").concat(dataItemId);
    },
    dataItemEditorDataItemUnit: 'Unit',
    dataItemEditorDataItemFilter: 'Data filter',
    dataItemEditorDataItemThresholds: 'Thresholds',
    dataItemEditorDataItemAddThreshold: 'Add threshold',
    dataItemEditorDataItemTooltip: 'Tooltip',
    dataItemEditorBarColor: 'Bar color',
    dataItemEditorLineColor: 'Line color',
    dataItemEditorAddAggregationMethodLabel: 'Add aggregation method',
    dataItemEditorAddAggregationMethodDescription: 'Add aggregation method',
    source: 'Source data item',
    aggregationMethod: 'Aggregation method',
    grain: 'Grain',
    hourlyLabel: 'Hourly',
    dailyLabel: 'Daily',
    weeklyLabel: 'Weekly',
    monthlyLabel: 'Monthly',
    yearlyLabel: 'Yearly',
    dataItemSource: 'Data item source',
    primaryButtonLabelText: 'Save',
    secondaryButtonLabelText: 'Cancel',
    decimalPlacesLabel: 'Decimal places'
  },
  shouldUseTranslatedLabels: false,
  editDataSeries: [],
  showEditor: false,
  setShowEditor: null,
  availableDimensions: {},
  editDataItem: {
    columnType: undefined
  },
  setEditDataItem: null,
  isSummaryDashboard: false,
  isLarge: false,
  validDataItems: [],
  actions: editorUtils.defaultDashboardEditorActionsProps,
  handleDataItemEdit: editorUtils.handleDefaultDataItemEdit,
  options: {
    hasColorDropdown: false,
    hasUnit: false,
    hasDecimalPlacesDropdown: false,
    hasThresholds: false,
    hasTooltip: false
  }
};
var DATAITEM_COLORS_OPTIONS = [{
  carbonColor: colors.purple70,
  name: 'purple70'
}, {
  carbonColor: colors.cyan50,
  name: 'cyan50'
}, {
  carbonColor: colors.teal70,
  name: 'teal70'
}, {
  carbonColor: colors.magenta70,
  name: 'magenta70'
}, {
  carbonColor: colors.red50,
  name: 'red50'
}, {
  carbonColor: colors.red90,
  name: 'red90'
}, {
  carbonColor: colors.green60,
  name: 'green60'
}, {
  carbonColor: colors.blue80,
  name: 'blue80'
}, {
  carbonColor: colors.magenta50,
  name: 'magenta50'
}, {
  carbonColor: colors.purple50,
  name: 'purple50'
}, {
  carbonColor: colors.teal50,
  name: 'teal50'
}, {
  carbonColor: colors.cyan90,
  name: 'cyan90'
}];
var DataSeriesFormItemModal = function DataSeriesFormItemModal(_ref) {
  var cardConfig = _ref.cardConfig,
    isSummaryDashboard = _ref.isSummaryDashboard,
    showEditor = _ref.showEditor,
    editDataSeries = _ref.editDataSeries,
    setShowEditor = _ref.setShowEditor,
    editDataItem = _ref.editDataItem,
    setEditDataItem = _ref.setEditDataItem,
    validDataItems = _ref.validDataItems,
    availableDimensions = _ref.availableDimensions,
    onChange = _ref.onChange,
    i18n = _ref.i18n,
    shouldUseTranslatedLabels = _ref.shouldUseTranslatedLabels,
    isLarge = _ref.isLarge,
    _ref$actions$dataSeri = _ref.actions.dataSeriesFormActions,
    hasAggregationsDropDown = _ref$actions$dataSeri.hasAggregationsDropDown,
    hasGrainsDropDown = _ref$actions$dataSeri.hasGrainsDropDown,
    hasDataFilterDropdown = _ref$actions$dataSeri.hasDataFilterDropdown,
    handleDataItemEdit = _ref.handleDataItemEdit,
    options = _ref.options;
  var mergedI18n = _objectSpread(_objectSpread({}, defaultProps.i18n), i18n);
  var id = cardConfig.id,
    type = cardConfig.type;
  var baseClassName = "".concat(iotPrefix, "--card-edit-form");
  var hasColorDropdown = options.hasColorDropdown,
    hasUnit = options.hasUnit,
    hasDecimalPlacesDropdown = options.hasDecimalPlacesDropdown,
    hasThresholds = options.hasThresholds,
    hasTooltip = options.hasTooltip;
  var isTimeBasedCard = cardUtilityFunctions.isTimeBasedCard(cardConfig);
  var handleTranslation = React.useCallback(function (idToTranslate) {
    var clearSelectionText = mergedI18n.clearSelectionText,
      openMenuText = mergedI18n.openMenuText,
      closeMenuText = mergedI18n.closeMenuText,
      clearAllText = mergedI18n.clearAllText,
      incrementNumberText = mergedI18n.incrementNumberText,
      decrementNumberText = mergedI18n.decrementNumberText;
    switch (idToTranslate) {
      case 'clear.all':
        return clearAllText || 'Clear all';
      case 'clear.selection':
        return clearSelectionText || 'Clear selection';
      case 'open.menu':
        return openMenuText || 'Open menu';
      case 'close.menu':
        return closeMenuText || 'Close menu';
      case 'increment.number':
        return incrementNumberText || 'Increment number';
      case 'decrement.number':
        return decrementNumberText || 'Decrement number';
      default:
        return '';
    }
  }, [mergedI18n]);
  var availableGrains = [{
    id: 'hourly',
    text: mergedI18n.hourlyLabel
  }, {
    id: 'daily',
    text: mergedI18n.dailyLabel
  }, {
    id: 'weekly',
    text: mergedI18n.weeklyLabel
  }, {
    id: 'monthly',
    text: mergedI18n.monthlyLabel
  }, {
    id: 'yearly',
    text: mergedI18n.yearlyLabel
  }];
  var matchedDataItem = validDataItems === null || validDataItems === void 0 ? void 0 : validDataItems.find(function (_ref2) {
    var dataSourceId = _ref2.dataSourceId;
    return dataSourceId === editDataItem.dataSourceId;
  });
  var initialAggregation = matchedDataItem === null || matchedDataItem === void 0 ? void 0 : matchedDataItem.aggregationMethod;
  var initialGrain = matchedDataItem === null || matchedDataItem === void 0 ? void 0 : matchedDataItem.grain;
  var selectedDimensionFilter = React.useMemo(function () {
    return editDataItem.dataFilter ? Object.keys(editDataItem.dataFilter)[0] : '';
  }, [editDataItem.dataFilter]);
  var availableDimensionsItems = React.useMemo(function () {
    var _availableDimensions$;
    return selectedDimensionFilter && ((_availableDimensions$ = availableDimensions[selectedDimensionFilter]) === null || _availableDimensions$ === void 0 ? void 0 : _availableDimensions$.sort().map(function (item) {
      return {
        id: item,
        text: item.toString()
      };
    })) || [];
  }, [availableDimensions, selectedDimensionFilter]);
  var DataEditorContent = React.useMemo(function () {
    var _editDataItem$aggrega, _editDataItem$aggrega2, _editDataItem$precisi;
    return /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, hasAggregationsDropDown && hasAggregationsDropDown(editDataItem) && /*#__PURE__*/React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group")
    }, !initialAggregation || !isSummaryDashboard ?
    /*#__PURE__*/
    // selector should only be use-able in an instance dash or if there is no initial aggregation
    React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group--item-half")
    }, /*#__PURE__*/React__default.default.createElement(react.Dropdown, {
      id: "".concat(id, "_aggregation-method"),
      label: "",
      direction: "bottom",
      itemToString: function itemToString(item) {
        return item.text;
      },
      items: editDataItem.aggregationMethods || [],
      selectedItem: ((_editDataItem$aggrega = editDataItem.aggregationMethods) === null || _editDataItem$aggrega === void 0 ? void 0 : _editDataItem$aggrega.find(function (method) {
        return method.id === editDataItem.aggregationMethod;
      })) || {
        id: 'none',
        text: mergedI18n.none
      },
      titleText: mergedI18n.aggregationMethod,
      light: true,
      onChange: function onChange(_ref3) {
        var _availableGrains$;
        var selectedItem = _ref3.selectedItem;
        setEditDataItem(omit.apply(void 0, [_objectSpread(_objectSpread({}, editDataItem), {}, {
          aggregationMethod: selectedItem.id
        }, isTimeBasedCard && selectedItem.id !== 'none' && !editDataItem.grain ? {
          grain: (_availableGrains$ = availableGrains[0]) === null || _availableGrains$ === void 0 ? void 0 : _availableGrains$.id
        } : {})].concat(_toConsumableArray__default.default(selectedItem.id === 'none' ? ['grain'] : []))));
      },
      autoAlign: true
    })) : /*#__PURE__*/React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group--item-half")
    }, /*#__PURE__*/React__default.default.createElement(react.FormLabel, {
      className: "".concat(baseClassName, "--input-group--item-half-label")
    }, mergedI18n.aggregationMethod), /*#__PURE__*/React__default.default.createElement("span", {
      className: "".concat(baseClassName, "--input-group--item-half-content")
    }, "".concat(editDataItem.aggregationMethod ? editDataItem.aggregationMethod[0].toUpperCase() : '').concat(((_editDataItem$aggrega2 = editDataItem.aggregationMethod) === null || _editDataItem$aggrega2 === void 0 ? void 0 : _editDataItem$aggrega2.slice(1)) || ''))), hasGrainsDropDown && hasGrainsDropDown(cardConfig, editDataItem) ? /*#__PURE__*/React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group--item-half")
    }, /*#__PURE__*/React__default.default.createElement(react.Dropdown, {
      id: "".concat(id, "_grain-selector"),
      label: "",
      direction: "bottom",
      itemToString: function itemToString(item) {
        return item.text;
      },
      items: isSummaryDashboard && initialAggregation // limit options for aggregated metrics in a summary dash
      ? availableGrains.slice(availableGrains.findIndex(function (grain) {
        return grain.id === initialGrain;
      })) : availableGrains,
      selectedItem: availableGrains.find(function (grain) {
        return grain.id === editDataItem.grain;
      }) || availableGrains[0],
      titleText: mergedI18n.grain,
      light: true,
      onChange: function onChange(_ref4) {
        var selectedItem = _ref4.selectedItem;
        setEditDataItem(_objectSpread(_objectSpread({}, editDataItem), {}, {
          grain: selectedItem.id
        }));
      },
      autoAlign: true
    })) : /*#__PURE__*/React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group--item-half")
    })), /*#__PURE__*/React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group")
    }, /*#__PURE__*/React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group--item")
    }, /*#__PURE__*/React__default.default.createElement(react.TextInput, {
      id: "".concat(id, "_attribute-label"),
      labelText: mergedI18n.dataItemEditorDataItemCustomLabel,
      light: true,
      onChange: function onChange(evt) {
        return setEditDataItem(_objectSpread(_objectSpread({}, editDataItem), {}, {
          label: evt.target.value
        }));
      },
      value: cardUtilityFunctions.getTranslatedLabel(editDataItem.label, shouldUseTranslatedLabels, i18n),
      helperText: mergedI18n.dataItemEditorDataItemHelperText(mergedI18n.dataItemSource, editDataItem.dataItemId)
    })), hasColorDropdown &&
    /*#__PURE__*/
    // show color selector
    React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group--item")
    }, /*#__PURE__*/React__default.default.createElement(ColorDropdown, {
      id: "".concat(id, "_color-dropdown"),
      label: "",
      titleText: type === LayoutConstants.CARD_TYPES.TIMESERIES ? mergedI18n.dataItemEditorLineColor : mergedI18n.dataItemEditorBarColor,
      selectedColor: DATAITEM_COLORS_OPTIONS.find(function (_ref5) {
        var carbonColor = _ref5.carbonColor;
        return carbonColor === editDataItem.color;
      }),
      onChange: function onChange(_ref6) {
        var color = _ref6.color;
        return setEditDataItem(_objectSpread(_objectSpread({}, editDataItem), {}, {
          color: color.carbonColor
        }));
      }
    })), hasTooltip && /*#__PURE__*/React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group--item")
    }, /*#__PURE__*/React__default.default.createElement(react.TextInput, {
      id: "".concat(id, "_attribute-tooltip"),
      labelText: mergedI18n.dataItemEditorDataItemTooltip,
      light: true,
      onChange: function onChange(evt) {
        return setEditDataItem(_objectSpread(_objectSpread({}, editDataItem), {}, {
          tooltip: evt.target.value
        }));
      },
      value: editDataItem.tooltip
    }))), (hasUnit || hasDecimalPlacesDropdown) && /*#__PURE__*/React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group")
    }, hasUnit && /*#__PURE__*/React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group--item")
    }, /*#__PURE__*/React__default.default.createElement(react.TextInput, {
      id: "".concat(id, "_attribute-unit"),
      labelText: mergedI18n.dataItemEditorDataItemUnit,
      light: true,
      placeholder: "".concat(mergedI18n.example, ": %"),
      onChange: function onChange(evt) {
        return setEditDataItem(_objectSpread(_objectSpread({}, editDataItem), {}, {
          unit: evt.target.value
        }));
      },
      value: cardUtilityFunctions.getTranslatedLabel(editDataItem.unit, shouldUseTranslatedLabels, i18n)
    })), /*#__PURE__*/React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group--item")
    }, hasDecimalPlacesDropdown && /*#__PURE__*/React__default.default.createElement(react.Dropdown, {
      id: "".concat(id, "_value-card-decimal-place"),
      titleText: mergedI18n.decimalPlacesLabel,
      direction: "bottom",
      label: "",
      items: [mergedI18n.notSet, '0', '1', '2', '3', '4'],
      light: true,
      selectedItem: ((_editDataItem$precisi = editDataItem.precision) === null || _editDataItem$precisi === void 0 ? void 0 : _editDataItem$precisi.toString()) || mergedI18n.notSet,
      onChange: function onChange(_ref7) {
        var selectedItem = _ref7.selectedItem;
        var isSet = selectedItem !== mergedI18n.notSet;
        if (isSet) {
          setEditDataItem(_objectSpread(_objectSpread({}, editDataItem), {}, {
            precision: Number(selectedItem)
          }));
        } else {
          setEditDataItem(omit(editDataItem, 'precision'));
        }
      },
      autoAlign: true
    }))), hasDataFilterDropdown && hasDataFilterDropdown(cardConfig) &&
    /*#__PURE__*/
    // only show data filter in summary dashboards or instance dashboard for DEVICE_TYPE
    React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group ").concat(baseClassName, "--input-group--bottom ")
    }, /*#__PURE__*/React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group--item")
    }, /*#__PURE__*/React__default.default.createElement(react.Dropdown, {
      id: "".concat(id, "_data-filter-key"),
      label: "",
      translateWithId: handleTranslation,
      direction: "bottom",
      items: [mergedI18n.none].concat(_toConsumableArray__default.default(Object.keys(availableDimensions))),
      light: true,
      selectedItem: selectedDimensionFilter || mergedI18n.none,
      onChange: function onChange(_ref8) {
        var selectedItem = _ref8.selectedItem;
        if (selectedItem !== mergedI18n.none) {
          var dataFilter = _defineProperty__default.default({}, selectedItem, availableDimensions[selectedItem].sort()[0]);
          setEditDataItem(_objectSpread(_objectSpread({}, editDataItem), {}, {
            dataFilter: dataFilter
          }));
        } else {
          setEditDataItem(_objectSpread({}, omit(editDataItem, 'dataFilter')));
        }
      },
      titleText: mergedI18n.dataItemEditorDataItemFilter,
      autoAlign: true
    })), /*#__PURE__*/React__default.default.createElement("div", {
      className: "".concat(baseClassName, "--input-group--item")
    }, !isEmpty(editDataItem.dataFilter) && (availableDimensionsItems === null || availableDimensionsItems === void 0 ? void 0 : availableDimensionsItems.length) > 0 && /*#__PURE__*/React__default.default.createElement(react.Dropdown, {
      id: "".concat(id, "_data-filter-value"),
      label: "",
      direction: "bottom",
      items: availableDimensionsItems,
      light: true,
      itemToString: function itemToString(item) {
        return item ? item.text : '';
      },
      selectedItem: availableDimensionsItems.find(function (item) {
        var _editDataItem$dataFil;
        return item.id === ((_editDataItem$dataFil = editDataItem.dataFilter) === null || _editDataItem$dataFil === void 0 ? void 0 : _editDataItem$dataFil[selectedDimensionFilter]);
      }),
      onChange: function onChange(_ref9) {
        var selectedItem = _ref9.selectedItem;
        var dataFilter = _defineProperty__default.default({}, selectedDimensionFilter, selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.id);
        setEditDataItem(_objectSpread(_objectSpread({}, editDataItem), {}, {
          dataFilter: dataFilter
        }));
      },
      autoAlign: true
    }))), hasThresholds && /*#__PURE__*/React__default.default.createElement(ThresholdsFormItem, {
      id: "".concat(id, "_thresholds"),
      i18n: mergedI18n,
      cardConfig: cardConfig,
      dataSourceId: type !== LayoutConstants.CARD_TYPES.VALUE ? editDataItem.dataSourceId : null,
      thresholds: editDataItem.thresholds,
      translateWithId: handleTranslation,
      selectedIcon: {
        carbonIcon: /*#__PURE__*/React__default.default.createElement(iconsReact.WarningAlt, {
          size: 32
        }),
        name: 'Warning alt'
      },
      selectedColor: {
        carbonColor: colors.red60,
        name: 'red60'
      },
      onChange: function onChange(thresholds) {
        setEditDataItem(_objectSpread(_objectSpread({}, editDataItem), {}, {
          thresholds: thresholds
        }));
      },
      columnType: editDataItem.columnType || editDataItem.type
    }));
  }, [availableDimensions, availableDimensionsItems, availableGrains, baseClassName, cardConfig, editDataItem, handleTranslation, hasAggregationsDropDown, hasColorDropdown, hasDataFilterDropdown, hasDecimalPlacesDropdown, hasGrainsDropDown, hasThresholds, hasTooltip, hasUnit, i18n, id, initialAggregation, initialGrain, isSummaryDashboard, isTimeBasedCard, mergedI18n, selectedDimensionFilter, setEditDataItem, shouldUseTranslatedLabels, type]);
  return /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, showEditor && /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(baseClassName, "--modal-wrapper")
  }, /*#__PURE__*/React__default.default.createElement(ComposedModal.default, {
    selectorPrimaryFocus: ".".concat(prefix, "--modal-header"),
    header: {
      label: editDataItem.dataItemId,
      title: type === LayoutConstants.CARD_TYPES.VALUE ? mergedI18n.dataItemEditorValueCardTitle : mergedI18n.dataItemEditorDataSeriesTitle
    },
    size: "md",
    isLarge: isLarge,
    footer: {
      primaryButtonLabel: mergedI18n.primaryButtonLabelText,
      secondaryButtonLabel: mergedI18n.secondaryButtonLabelText
    },
    onSubmit: function onSubmit() {
      var newCard = cardConfig.type === LayoutConstants.CARD_TYPES.IMAGE ? editDataItem : handleDataItemEdit(editDataItem, cardConfig, editDataSeries);
      onChange(newCard);
      setShowEditor(false);
      setEditDataItem({});
    },
    iconDescription: mergedI18n.closeButtonLabelText,
    onClose: function onClose() {
      setShowEditor(false);
      setEditDataItem({});
    }
  }, DataEditorContent)));
};
DataSeriesFormItemModal.defaultProps = defaultProps;
DataSeriesFormItemModal.propTypes = propTypes;
DataSeriesFormItemModal.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "DataSeriesFormItemModal",
  "props": {
    "cardConfig": {
      "defaultValue": {
        "value": "{}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "id": {
            "name": "string",
            "required": false
          },
          "title": {
            "name": "string",
            "required": false
          },
          "size": {
            "name": "string",
            "required": false
          },
          "type": {
            "name": "string",
            "required": false
          },
          "content": {
            "name": "shape",
            "value": {
              "series": {
                "name": "arrayOf",
                "value": {
                  "name": "shape",
                  "value": {
                    "label": {
                      "name": "string",
                      "required": false
                    },
                    "dataSourceId": {
                      "name": "string",
                      "required": false
                    },
                    "color": {
                      "name": "string",
                      "required": false
                    }
                  }
                },
                "required": false
              },
              "columns": {
                "name": "arrayOf",
                "value": {
                  "name": "shape",
                  "value": {
                    "dataSourceId": {
                      "name": "string",
                      "required": false
                    },
                    "label": {
                      "name": "string",
                      "required": false
                    },
                    "type": {
                      "name": "string",
                      "required": false
                    },
                    "dataItemType": {
                      "name": "string",
                      "required": false
                    }
                  }
                },
                "required": false
              },
              "type": {
                "name": "string",
                "required": false
              },
              "xLabel": {
                "name": "string",
                "required": false
              },
              "yLabel": {
                "name": "string",
                "required": false
              },
              "unit": {
                "name": "string",
                "required": false
              },
              "includeZeroOnXaxis": {
                "name": "bool",
                "required": false
              },
              "includeZeroOnYaxis": {
                "name": "bool",
                "required": false
              },
              "timeDataSourceId": {
                "name": "string",
                "required": false
              }
            },
            "required": false
          },
          "interval": {
            "name": "string",
            "required": false
          },
          "showLegend": {
            "name": "bool",
            "required": false
          }
        }
      },
      "required": false
    },
    "i18n": {
      "defaultValue": {
        "value": "{\n  dataItemEditorDataSeriesTitle: 'Customize data series',\n  dataItemEditorValueCardTitle: 'Edit data',\n  dataItemEditorDataItemLabel: 'Label',\n  dataItemEditorLegendColor: 'Legend color',\n  dataItemEditorSectionTitle: 'Data series',\n  selectDataItems: 'Select data items',\n  dataItem: 'Data item',\n  edit: 'Edit',\n  example: 'Example',\n  notSet: 'Not set',\n  none: 'None',\n  dataItemEditorDataItemCustomLabel: 'Custom label',\n  dataItemEditorDataItemHelperText: (dataItemSource, dataItemId) =>\n    `${dataItemSource}: ${dataItemId}`,\n  dataItemEditorDataItemUnit: 'Unit',\n  dataItemEditorDataItemFilter: 'Data filter',\n  dataItemEditorDataItemThresholds: 'Thresholds',\n  dataItemEditorDataItemAddThreshold: 'Add threshold',\n  dataItemEditorDataItemTooltip: 'Tooltip',\n  dataItemEditorBarColor: 'Bar color',\n  dataItemEditorLineColor: 'Line color',\n  dataItemEditorAddAggregationMethodLabel: 'Add aggregation method',\n  dataItemEditorAddAggregationMethodDescription: 'Add aggregation method',\n  source: 'Source data item',\n  aggregationMethod: 'Aggregation method',\n  grain: 'Grain',\n  hourlyLabel: 'Hourly',\n  dailyLabel: 'Daily',\n  weeklyLabel: 'Weekly',\n  monthlyLabel: 'Monthly',\n  yearlyLabel: 'Yearly',\n  dataItemSource: 'Data item source',\n  primaryButtonLabelText: 'Save',\n  secondaryButtonLabelText: 'Cancel',\n  decimalPlacesLabel: 'Decimal places',\n}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "dataItemEditorDataItemTitle": {
            "name": "string",
            "required": false
          },
          "dataItemEditorDataItemLabel": {
            "name": "string",
            "required": false
          },
          "dataItemEditorLegendColor": {
            "name": "string",
            "required": false
          },
          "dataItemEditorSectionTitle": {
            "name": "string",
            "required": false
          },
          "selectDataItems": {
            "name": "string",
            "required": false
          },
          "dataItem": {
            "name": "string",
            "required": false
          },
          "edit": {
            "name": "string",
            "required": false
          },
          "dataItemEditorDataItemCustomLabel": {
            "name": "string",
            "required": false
          },
          "dataItemEditorDataItemHelperText": {
            "name": "func",
            "description": "Function receiving the dataItemSource & dataItemId as params:\n(dataItemSource, dataItemId) => `${dataItemSource}: ${dataItemId}`",
            "required": false
          },
          "dataItemEditorDataItemUnit": {
            "name": "string",
            "required": false
          },
          "dataItemEditorDataItemFilter": {
            "name": "string",
            "required": false
          },
          "dataItemEditorDataItemThresholds": {
            "name": "string",
            "required": false
          },
          "dataItemEditorDataItemAddThreshold": {
            "name": "string",
            "required": false
          },
          "source": {
            "name": "string",
            "required": false
          },
          "primaryButtonLabelText": {
            "name": "string",
            "required": false
          },
          "secondaryButtonLabelText": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "shouldUseTranslatedLabels": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "whether to use translated labels in cards",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "editDataSeries": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": {
            "dataSourceId": {
              "name": "string",
              "required": false
            },
            "label": {
              "name": "string",
              "required": false
            },
            "color": {
              "name": "string",
              "required": false
            }
          }
        }
      },
      "required": false
    },
    "showEditor": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "setShowEditor": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "func"
      },
      "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
    },
    "editDataItem": {
      "defaultValue": {
        "value": "{\n  columnType: undefined,\n}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "columnType": {
            "name": "enum",
            "value": [{
              "value": "'LITERAL'",
              "computed": false
            }, {
              "value": "'BOOLEAN'",
              "computed": false
            }, {
              "value": "'TIMESTAMP'",
              "computed": false
            }, {
              "value": "'NUMBER'",
              "computed": false
            }],
            "required": false
          },
          "dataSourceId": {
            "name": "string",
            "required": false
          },
          "dataFilter": {
            "name": "objectOf",
            "value": {
              "name": "string"
            },
            "required": false
          },
          "type": {
            "name": "string",
            "description": "Maps to data item columnType",
            "required": false
          },
          "dataItemType": {
            "name": "string",
            "description": "Maps to data item type",
            "required": false
          },
          "aggregationMethods": {
            "name": "arrayOf",
            "value": {
              "name": "shape",
              "value": {
                "id": {
                  "name": "string",
                  "required": false
                },
                "text": {
                  "name": "string",
                  "required": false
                }
              }
            },
            "required": false
          },
          "aggregationMethod": {
            "name": "string",
            "required": false
          },
          "grain": {
            "name": "string",
            "required": false
          },
          "label": {
            "name": "string",
            "required": false
          },
          "dataItemId": {
            "name": "string",
            "required": false
          },
          "color": {
            "name": "string",
            "required": false
          },
          "unit": {
            "name": "string",
            "required": false
          },
          "precision": {
            "name": "number",
            "required": false
          },
          "thresholds": {
            "name": "arrayOf",
            "value": {
              "name": "shape",
              "value": {
                "color": {
                  "name": "string",
                  "required": false
                },
                "comparison": {
                  "name": "custom",
                  "raw": "PropTypes.stirng",
                  "required": false
                },
                "icon": {
                  "name": "string",
                  "required": false
                },
                "value": {
                  "name": "union",
                  "value": [{
                    "name": "bool"
                  }, {
                    "name": "number"
                  }, {
                    "name": "string"
                  }],
                  "required": false
                }
              }
            },
            "required": false
          },
          "tooltip": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "setEditDataItem": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "isSummaryDashboard": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "isLarge": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "validDataItems": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "custom",
        "raw": "DataItemsPropTypes"
      },
      "required": false
    },
    "actions": {
      "defaultValue": {
        "value": "defaultDashboardEditorActionsProps",
        "computed": true
      },
      "description": "",
      "type": {
        "name": "custom",
        "raw": "DashboardEditorActionsPropTypes"
      },
      "required": false
    },
    "handleDataItemEdit": {
      "defaultValue": {
        "value": "handleDefaultDataItemEdit",
        "computed": true
      },
      "description": "Used to override the default behaviour of handleDataItemEdit. if we dont pass any function then it uses handleDefaultDataItemEdit function by default",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "options": {
      "defaultValue": {
        "value": "{\n  hasColorDropdown: false,\n  hasUnit: false,\n  hasDecimalPlacesDropdown: false,\n  hasThresholds: false,\n  hasTooltip: false,\n}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "hasColorDropdown": {
            "name": "bool",
            "required": false
          },
          "hasUnit": {
            "name": "bool",
            "required": false
          },
          "hasDecimalPlacesDropdown": {
            "name": "bool",
            "required": false
          },
          "hasThresholds": {
            "name": "bool",
            "required": false
          },
          "hasTooltip": {
            "name": "bool",
            "required": false
          }
        }
      },
      "required": false
    },
    "onChange": {
      "description": "",
      "type": {
        "name": "func"
      },
      "required": true
    }
  }
};
var DataSeriesFormItemModal$1 = DataSeriesFormItemModal;

module.exports = DataSeriesFormItemModal$1;
