"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _useGeneratedId = _interopRequireDefault(require("../hooks/useGeneratedId"));

var _Slider = _interopRequireDefault(require("../Slider"));

var _Text = _interopRequireDefault(require("../Text"));

var _Box = _interopRequireDefault(require("../Box"));

var _FormGroup = _interopRequireWildcard(require("../FormGroup"));

var SliderField = function SliderField(_ref) {
  var idProp = _ref.id,
      Value = _ref.renderValue,
      label = _ref.label,
      hasError = _ref.hasError,
      disabled = _ref.disabled,
      readOnly = _ref.readOnly,
      hint = _ref.hint,
      value = _ref.value,
      rest = (0, _objectWithoutPropertiesLoose2.default)(_ref, ["id", "renderValue", "label", "hasError", "disabled", "readOnly", "hint", "value"]);
  var generatedStub = (0, _useGeneratedId.default)();
  var generatedId = "field-" + generatedStub;
  var id = idProp || generatedId;
  var variant = (0, _FormGroup.getVariant)({
    disabled: disabled,
    readOnly: readOnly,
    hasError: hasError
  });
  return _react.default.createElement(_Box.default, {
    sx: {
      position: 'relative'
    }
  }, _react.default.createElement(_Text.default, {
    sx: {
      textAlign: 'right',
      position: ['absolute', 'absolute', 'static'],
      right: 0,
      top: 0
    },
    mb: 0
  }, Value ? _react.default.createElement(Value, null, value) : value), _react.default.createElement(_FormGroup.default, {
    id: id,
    label: label,
    hint: hint,
    disabled: disabled,
    readOnly: readOnly,
    hasError: hasError
  }, _react.default.createElement(_Slider.default, (0, _extends2.default)({
    variant: variant ? "forms.slider." + variant : 'forms.slider.default',
    disabled: disabled,
    readOnly: readOnly,
    id: id,
    value: value
  }, rest))));
};

SliderField.propTypes = {
  /** Disabled state */
  disabled: _propTypes.default.bool,

  /** Error state */
  hasError: _propTypes.default.bool,

  /** Hint itext */
  hint: _propTypes.default.node,

  /** Used to connect label and slider. If not defined, component will generate its own. */
  id: _propTypes.default.string,

  /** Label for Slider  */
  label: _propTypes.default.node,

  /** Called when `onChange` event is triggered. */
  onChange: _propTypes.default.func,

  /** Read-only state */
  readOnly: _propTypes.default.bool,

  /** Formattting component for the value */
  renderValue: _propTypes.default.elementType,

  /** Current value of checkbox. */
  value: _propTypes.default.any
};
var _default = SliderField;
exports.default = _default;