'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var omit = require('../../../../../node_modules/lodash-es/omit.js');
require('core-js/modules/es.symbol.js');
require('core-js/modules/es.array.filter.js');
require('core-js/modules/es.number.is-nan.js');
require('core-js/modules/es.number.parse-int.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 React = require('react');
var PropTypes = require('prop-types');
var react = require('@carbon/react');
var Settings = require('../../../../../constants/Settings.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 iotPrefix = Settings.settings.iotPrefix;
var propTypes = {
  /** 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
      })),
      layout: PropTypes__default.default.string,
      decimalPrecision: PropTypes__default.default.number,
      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,
      maximumDataPoints: PropTypes__default.default.number
    }),
    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,
    showLegendLabel: PropTypes__default.default.string,
    fontSize: PropTypes__default.default.string,
    precisionLabel: PropTypes__default.default.string,
    layoutLabel: PropTypes__default.default.string,
    autoLabel: PropTypes__default.default.string,
    horizontal: PropTypes__default.default.string,
    vertical: PropTypes__default.default.string,
    maximumDataPoints: PropTypes__default.default.string
  })
};
var defaultProps = {
  cardConfig: {},
  i18n: {
    xAxisLabel: 'X-axis label',
    yAxisLabel: 'Y-axis label',
    unitLabel: 'Unit',
    decimalPrecisionLabel: 'Decimal precision',
    showLegendLabel: 'Show legend',
    fontSize: 'Font size',
    precisionLabel: 'Precision',
    layoutLabel: 'Layout',
    autoLabel: 'Auto',
    horizontal: 'Horizontal',
    vertical: 'Vertical',
    maximumDataPoints: 'Maximum data points'
  }
};
var BarChartCardFormSettings = function BarChartCardFormSettings(_ref) {
  var _cardConfig$content;
  var cardConfig = _ref.cardConfig,
    _onChange = _ref.onChange,
    i18n = _ref.i18n;
  var mergedI18n = _objectSpread(_objectSpread({}, defaultProps.i18n), i18n);
  var content = cardConfig.content,
    id = cardConfig.id;
  var baseClassName = "".concat(iotPrefix, "--card-edit-form");
  return /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(baseClassName, "--input")
  }, /*#__PURE__*/React__default.default.createElement(react.FormGroup, {
    legendText: mergedI18n.layoutLabel
  }, /*#__PURE__*/React__default.default.createElement(react.RadioButtonGroup, {
    name: "".concat(baseClassName, "--layout-radios"),
    onChange: function onChange(layout) {
      _onChange(_objectSpread(_objectSpread({}, cardConfig), {}, {
        content: _objectSpread(_objectSpread({}, cardConfig.content), {}, {
          layout: layout
        })
      }));
    },
    orientation: "vertical",
    legend: mergedI18n.layoutLabel,
    valueSelected: (_cardConfig$content = cardConfig.content) === null || _cardConfig$content === void 0 ? void 0 : _cardConfig$content.layout
  }, /*#__PURE__*/React__default.default.createElement(react.RadioButton, {
    "data-testid": "".concat(baseClassName, "--layout-radio1"),
    value: "HORIZONTAL",
    id: "".concat(baseClassName, "--layout-radio-1"),
    labelText: mergedI18n.horizontal
  }), /*#__PURE__*/React__default.default.createElement(react.RadioButton, {
    "data-testid": "".concat(baseClassName, "--layout-radio2"),
    value: "VERTICAL",
    id: "".concat(baseClassName, "--layout-radio-2"),
    labelText: mergedI18n.vertical
  })))), /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(baseClassName, "--input")
  }, /*#__PURE__*/React__default.default.createElement(react.TextInput, {
    id: "".concat(id, "_y-axis-label"),
    labelText: mergedI18n.yAxisLabel,
    light: true,
    onChange: function onChange(evt) {
      return _onChange(_objectSpread(_objectSpread({}, cardConfig), {}, {
        content: _objectSpread(_objectSpread({}, cardConfig.content), {}, {
          yLabel: evt.target.value
        })
      }));
    },
    value: content === null || content === void 0 ? void 0 : content.yLabel
  })), /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(baseClassName, "--input")
  }, /*#__PURE__*/React__default.default.createElement(react.TextInput, {
    id: "".concat(id, "_x-axis-label"),
    labelText: mergedI18n.xAxisLabel,
    light: true,
    onChange: function onChange(evt) {
      return _onChange(_objectSpread(_objectSpread({}, cardConfig), {}, {
        content: _objectSpread(_objectSpread({}, cardConfig.content), {}, {
          xLabel: evt.target.value
        })
      }));
    },
    value: content === null || content === void 0 ? void 0 : content.xLabel
  })), /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(baseClassName, "--input")
  }, /*#__PURE__*/React__default.default.createElement(react.Layer, null, /*#__PURE__*/React__default.default.createElement(react.NumberInput, {
    id: "".concat(id, "_decimal-precision"),
    label: mergedI18n.decimalPrecisionLabel,
    min: 0,
    max: 100,
    onChange: function onChange(event, _ref2) {
      var value = _ref2.value;
      var decimalPrecision = Number.parseInt(value, 10);
      _onChange(_objectSpread(_objectSpread({}, cardConfig), {}, {
        content: _objectSpread(_objectSpread({}, omit(cardConfig.content, 'decimalPrecision')), Number.isNaN(decimalPrecision) || decimalPrecision < 0 ? {} : {
          decimalPrecision: decimalPrecision
        })
      }));
    },
    value: content === null || content === void 0 ? void 0 : content.decimalPrecision
  }))), /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(baseClassName, "--input")
  }, /*#__PURE__*/React__default.default.createElement(react.Layer, null, /*#__PURE__*/React__default.default.createElement(react.NumberInput, {
    id: "".concat(id, "_maximum_data_points"),
    label: mergedI18n.maximumDataPoints,
    step: 10,
    min: 0,
    onChange: function onChange(event, _ref3) {
      var value = _ref3.value;
      var maximumDataPoints = Number.parseInt(value, 10);
      _onChange(_objectSpread(_objectSpread({}, cardConfig), {}, {
        content: _objectSpread(_objectSpread({}, cardConfig.content), {}, {
          maximumDataPoints: maximumDataPoints < 0 ? 0 : maximumDataPoints
        })
      }));
    },
    value: content === null || content === void 0 ? void 0 : content.maximumDataPoints
  }))));
};
BarChartCardFormSettings.propTypes = propTypes;
BarChartCardFormSettings.defaultProps = defaultProps;
BarChartCardFormSettings.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "BarChartCardFormSettings",
  "props": {
    "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
              },
              "layout": {
                "name": "string",
                "required": false
              },
              "decimalPrecision": {
                "name": "number",
                "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
              },
              "maximumDataPoints": {
                "name": "number",
                "required": false
              }
            },
            "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  showLegendLabel: 'Show legend',\n  fontSize: 'Font size',\n  precisionLabel: 'Precision',\n  layoutLabel: 'Layout',\n  autoLabel: 'Auto',\n  horizontal: 'Horizontal',\n  vertical: 'Vertical',\n  maximumDataPoints: 'Maximum data points',\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
          },
          "showLegendLabel": {
            "name": "string",
            "required": false
          },
          "fontSize": {
            "name": "string",
            "required": false
          },
          "precisionLabel": {
            "name": "string",
            "required": false
          },
          "layoutLabel": {
            "name": "string",
            "required": false
          },
          "autoLabel": {
            "name": "string",
            "required": false
          },
          "horizontal": {
            "name": "string",
            "required": false
          },
          "vertical": {
            "name": "string",
            "required": false
          },
          "maximumDataPoints": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "onChange": {
      "description": "Callback function when form data changes",
      "type": {
        "name": "func"
      },
      "required": true
    }
  }
};
var BarChartCardFormSettings$1 = BarChartCardFormSettings;

module.exports = BarChartCardFormSettings$1;
