import _defineProperty from '@babel/runtime/helpers/defineProperty';
import 'core-js/modules/es.symbol.js';
import 'core-js/modules/es.array.filter.js';
import 'core-js/modules/es.number.constructor.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 { Layer, NumberInput, Toggle } from '@carbon/react';
import { settings } from '../../../../../constants/Settings.js';
import { Tooltip } from '../../../../Tooltip/index.js';
import { DEFAULT_FONT_SIZE } from '../../../../ValueCard/valueCardUtils.js';
import { isNumberValidForMinMax } from '../../../../../utils/componentUtilityFunctions.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
      })),
      unit: PropTypes.string
    }),
    interval: PropTypes.string,
    fontSize: PropTypes.number,
    isNumberValueCompact: PropTypes.bool
  }),
  /** Callback function when form data changes */
  onChange: PropTypes.func.isRequired,
  i18n: PropTypes.shape({
    fontSize: PropTypes.string,
    abbreviateNumbers: PropTypes.string,
    abbreviateNumbersTooltip: PropTypes.string
  })
};
var defaultProps = {
  cardConfig: {},
  i18n: {
    fontSize: 'Font size',
    abbreviateNumbers: 'Abbreviate numbers',
    abbreviateNumbersTooltip: 'Shorten numbers by using K, M, B. For example, shows "1.2K" instead of "1,200"'
  }
};
var MIN_FONT_SIZE = 16;
var MAX_FONT_SIZE = 54;
var ValueCardFormSettings = function ValueCardFormSettings(_ref) {
  var cardConfig = _ref.cardConfig,
    _onChange = _ref.onChange,
    i18n = _ref.i18n;
  var mergedI18n = _objectSpread(_objectSpread({}, defaultProps.i18n), i18n);
  var id = cardConfig.id,
    fontSize = cardConfig.fontSize,
    isNumberValueCompact = cardConfig.isNumberValueCompact;
  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(Layer, null, /*#__PURE__*/React__default.createElement(NumberInput, {
    id: "".concat(id, "_value-card-font-size"),
    step: 1,
    min: MIN_FONT_SIZE,
    max: MAX_FONT_SIZE,
    label: mergedI18n.fontSize,
    value: fontSize || DEFAULT_FONT_SIZE,
    onChange: function onChange(event, _ref2) {
      var value = _ref2.value;
      var parsedValue = Number(value !== null && value !== void 0 ? value : event.imaginaryTarget.value);
      if (isNumberValidForMinMax(parsedValue, MIN_FONT_SIZE, MAX_FONT_SIZE)) {
        _onChange(_objectSpread(_objectSpread({}, cardConfig), {}, {
          fontSize: parsedValue
        }));
      }
    }
  }))), /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(baseClassName, "--input")
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(baseClassName, "--input--toggle-field")
  }, /*#__PURE__*/React__default.createElement("span", null, mergedI18n.abbreviateNumbers), /*#__PURE__*/React__default.createElement(Tooltip, {
    direction: "left",
    triggerText: null,
    triggerId: "".concat(id, "-abbreviate-numbers-tooltip"),
    useAutoPositioning: true
  }, mergedI18n.abbreviateNumbersTooltip), /*#__PURE__*/React__default.createElement(Toggle, {
    size: "sm",
    id: "".concat(id, "_value-card-number-compact"),
    labelA: "",
    labelB: "",
    toggled: isNumberValueCompact || false,
    onToggle: function onToggle(toggled) {
      return _onChange(_objectSpread(_objectSpread({}, cardConfig), {}, {
        isNumberValueCompact: toggled
      }));
    },
    "aria-label": "Abbreviate number"
  }))));
};
ValueCardFormSettings.propTypes = propTypes;
ValueCardFormSettings.defaultProps = defaultProps;
ValueCardFormSettings.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "ValueCardFormSettings",
  "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
              },
              "unit": {
                "name": "string",
                "required": false
              }
            },
            "required": false
          },
          "interval": {
            "name": "string",
            "required": false
          },
          "fontSize": {
            "name": "number",
            "required": false
          },
          "isNumberValueCompact": {
            "name": "bool",
            "required": false
          }
        }
      },
      "required": false
    },
    "i18n": {
      "defaultValue": {
        "value": "{\n  fontSize: 'Font size',\n  abbreviateNumbers: 'Abbreviate numbers',\n  abbreviateNumbersTooltip:\n    'Shorten numbers by using K, M, B. For example, shows \"1.2K\" instead of \"1,200\"',\n}",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "shape",
        "value": {
          "fontSize": {
            "name": "string",
            "required": false
          },
          "abbreviateNumbers": {
            "name": "string",
            "required": false
          },
          "abbreviateNumbersTooltip": {
            "name": "string",
            "required": false
          }
        }
      },
      "required": false
    },
    "onChange": {
      "description": "Callback function when form data changes",
      "type": {
        "name": "func"
      },
      "required": true
    }
  }
};
var ValueCardFormSettings$1 = ValueCardFormSettings;

export { ValueCardFormSettings$1 as default };
