import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _omit from '../../../../../node_modules/lodash-es/omit.js';
import 'core-js/modules/es.symbol.js';
import 'core-js/modules/es.array.filter.js';
import 'core-js/modules/es.number.is-nan.js';
import 'core-js/modules/es.number.parse-int.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/web.dom-collections.for-each.js';
import React__default from 'react';
import PropTypes from 'prop-types';
import { FormGroup, RadioButtonGroup, RadioButton, TextInput, Layer, NumberInput } from '@carbon/react';
import { settings } from '../../../../../constants/Settings.js';

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 = {
  /** card data value */
  cardConfig: PropTypes.shape({
    id: PropTypes.string,
    title: PropTypes.string,
    size: PropTypes.string,
    type: PropTypes.string,
    content: PropTypes.shape({
      series: PropTypes.arrayOf(PropTypes.shape({
        label: PropTypes.string,
        dataSourceId: PropTypes.string,
        color: PropTypes.string
      })),
      layout: PropTypes.string,
      decimalPrecision: PropTypes.number,
      xLabel: PropTypes.string,
      yLabel: PropTypes.string,
      unit: PropTypes.string,
      includeZeroOnXaxis: PropTypes.bool,
      includeZeroOnYaxis: PropTypes.bool,
      timeDataSourceId: PropTypes.string,
      showLegend: PropTypes.bool,
      maximumDataPoints: PropTypes.number
    }),
    interval: PropTypes.string
  }),
  /** Callback function when form data changes */
  onChange: PropTypes.func.isRequired,
  i18n: PropTypes.shape({
    xAxisLabel: PropTypes.string,
    yAxisLabel: PropTypes.string,
    unitLabel: PropTypes.string,
    decimalPrecisionLabel: PropTypes.string,
    showLegendLabel: PropTypes.string,
    fontSize: PropTypes.string,
    precisionLabel: PropTypes.string,
    layoutLabel: PropTypes.string,
    autoLabel: PropTypes.string,
    horizontal: PropTypes.string,
    vertical: PropTypes.string,
    maximumDataPoints: PropTypes.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.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(baseClassName, "--input")
  }, /*#__PURE__*/React__default.createElement(FormGroup, {
    legendText: mergedI18n.layoutLabel
  }, /*#__PURE__*/React__default.createElement(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.createElement(RadioButton, {
    "data-testid": "".concat(baseClassName, "--layout-radio1"),
    value: "HORIZONTAL",
    id: "".concat(baseClassName, "--layout-radio-1"),
    labelText: mergedI18n.horizontal
  }), /*#__PURE__*/React__default.createElement(RadioButton, {
    "data-testid": "".concat(baseClassName, "--layout-radio2"),
    value: "VERTICAL",
    id: "".concat(baseClassName, "--layout-radio-2"),
    labelText: mergedI18n.vertical
  })))), /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(baseClassName, "--input")
  }, /*#__PURE__*/React__default.createElement(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.createElement("div", {
    className: "".concat(baseClassName, "--input")
  }, /*#__PURE__*/React__default.createElement(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.createElement("div", {
    className: "".concat(baseClassName, "--input")
  }, /*#__PURE__*/React__default.createElement(Layer, null, /*#__PURE__*/React__default.createElement(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.createElement("div", {
    className: "".concat(baseClassName, "--input")
  }, /*#__PURE__*/React__default.createElement(Layer, null, /*#__PURE__*/React__default.createElement(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;

export { BarChartCardFormSettings$1 as default };
