'use strict';

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 LayoutConstants = require('../../../constants/LayoutConstants.js');
var DataSeriesFormSettings = require('./CardEditFormItems/DataSeriesFormItems/DataSeriesFormSettings.js');
var ValueCardFormSettings = require('./CardEditFormItems/ValueCardFormItems/ValueCardFormSettings.js');
var ImageCardFormSettings = require('./CardEditFormItems/ImageCardFormItems/ImageCardFormSettings.js');
var BarChartCardFormSettings = require('./CardEditFormItems/BarChartCardFormItems/BarChartCardFormSettings.js');
var TableCardFormSettings = require('./CardEditFormItems/TableCardFormItems/TableCardFormSettings.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 propTypes = {
  /** 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({}),
  /** card data 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
      })),
      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,
      showLegend: PropTypes__default.default.bool
    }),
    renderEditSettings: PropTypes__default.default.func,
    interval: PropTypes__default.default.string
  }),
  /** Callback function when form data changes */
  onChange: PropTypes__default.default.func.isRequired,
  i18n: PropTypes__default.default.shape({
    xAxisLabel: PropTypes__default.default.string,
    yAxisLabel: PropTypes__default.default.string,
    unitLabel: PropTypes__default.default.string,
    decimalPrecisionLabel: PropTypes__default.default.string,
    precisionLabel: PropTypes__default.default.string,
    showLegendLabel: PropTypes__default.default.string,
    fontSize: PropTypes__default.default.string
  })
};
var defaultProps = {
  availableDimensions: {},
  cardConfig: {},
  i18n: {
    xAxisLabel: 'X-axis label',
    yAxisLabel: 'Y-axis label',
    unitLabel: 'Unit',
    decimalPrecisionLabel: 'Decimal precision',
    precisionLabel: 'Precision',
    showLegendLabel: 'Show legend',
    fontSize: 'Font size'
  }
};
var CardEditFormSettings = function CardEditFormSettings(_ref) {
  var cardConfig = _ref.cardConfig,
    onChange = _ref.onChange,
    i18n = _ref.i18n,
    availableDimensions = _ref.availableDimensions;
  var mergedI18n = _objectSpread(_objectSpread({}, defaultProps.i18n), i18n);
  var type = cardConfig.type,
    renderEditSettings = cardConfig.renderEditSettings;
  var handleTranslation = React.useCallback(function (idToTranslate) {
    var openMenuText = mergedI18n.openMenuText,
      closeMenuText = mergedI18n.closeMenuText;
    switch (idToTranslate) {
      default:
        return '';
      case 'open.menu':
        return openMenuText || 'Open menu';
      case 'close.menu':
        return closeMenuText || 'Close menu';
    }
  }, [mergedI18n]);
  switch (type) {
    case LayoutConstants.CARD_TYPES.VALUE:
      return /*#__PURE__*/React__default.default.createElement(ValueCardFormSettings, {
        cardConfig: cardConfig,
        i18n: mergedI18n,
        onChange: onChange,
        translateWithId: handleTranslation
      });
    case LayoutConstants.CARD_TYPES.TIMESERIES:
      return /*#__PURE__*/React__default.default.createElement(DataSeriesFormSettings, {
        cardConfig: cardConfig,
        i18n: mergedI18n,
        onChange: onChange
      });
    case LayoutConstants.CARD_TYPES.BAR:
      return /*#__PURE__*/React__default.default.createElement(BarChartCardFormSettings, {
        cardConfig: cardConfig,
        i18n: mergedI18n,
        onChange: onChange
      });
    case LayoutConstants.CARD_TYPES.IMAGE:
      return /*#__PURE__*/React__default.default.createElement(ImageCardFormSettings, {
        cardConfig: cardConfig,
        i18n: mergedI18n,
        onChange: onChange,
        translateWithId: handleTranslation
      });
    case LayoutConstants.CARD_TYPES.TABLE:
      return /*#__PURE__*/React__default.default.createElement(TableCardFormSettings.default, {
        availableDimensions: availableDimensions,
        cardConfig: cardConfig,
        i18n: mergedI18n,
        onChange: onChange,
        translateWithId: handleTranslation
      });
    default:
      return renderEditSettings ? renderEditSettings(onChange, cardConfig) : null;
  }
};
CardEditFormSettings.propTypes = propTypes;
CardEditFormSettings.defaultProps = defaultProps;
CardEditFormSettings.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "CardEditFormSettings",
  "props": {
    "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
    },
    "cardConfig": {
      "defaultValue": {
        "value": "{}",
        "computed": false
      },
      "description": "card data value",
      "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
              },
              "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
              },
              "showLegend": {
                "name": "bool",
                "required": false
              }
            },
            "required": false
          },
          "renderEditSettings": {
            "name": "func",
            "required": false
          },
          "interval": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "i18n": {
      "defaultValue": {
        "value": "{\n  xAxisLabel: 'X-axis label',\n  yAxisLabel: 'Y-axis label',\n  unitLabel: 'Unit',\n  decimalPrecisionLabel: 'Decimal precision',\n  precisionLabel: 'Precision',\n  showLegendLabel: 'Show legend',\n  fontSize: 'Font size',\n}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "xAxisLabel": {
            "name": "string",
            "required": false
          },
          "yAxisLabel": {
            "name": "string",
            "required": false
          },
          "unitLabel": {
            "name": "string",
            "required": false
          },
          "decimalPrecisionLabel": {
            "name": "string",
            "required": false
          },
          "precisionLabel": {
            "name": "string",
            "required": false
          },
          "showLegendLabel": {
            "name": "string",
            "required": false
          },
          "fontSize": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "onChange": {
      "description": "Callback function when form data changes",
      "type": {
        "name": "func"
      },
      "required": true
    }
  }
};
var CardEditFormSettings$1 = CardEditFormSettings;

module.exports = CardEditFormSettings$1;
