"use strict";

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

var _react2 = require("@storybook/react");

var _addonKnobs = require("@storybook/addon-knobs");

var _reduxForm = require("redux-form");

var _configureStore2 = _interopRequireDefault(require("../../../storybook/configureStore"));

var _other = require("../../../storybook/reducers/other");

var _component = _interopRequireDefault(require("./component"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

var _configureStore = (0, _configureStore2.default)(),
    getState = _configureStore.getState,
    dispatch = _configureStore.dispatch;

var TestWrap = function TestWrap(_ref) {
  var children = _ref.children;
  return _react.default.createElement("form", null, children);
};

var RFWrap = (0, _reduxForm.reduxForm)({
  form: 'rf-wrap'
})(TestWrap);

var props = function props() {
  var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
      _ref2$isRFFWrap = _ref2.isRFFWrap,
      isRFFWrap = _ref2$isRFFWrap === void 0 ? undefined : _ref2$isRFFWrap,
      _ref2$label = _ref2.label,
      label = _ref2$label === void 0 ? undefined : _ref2$label,
      _ref2$value = _ref2.value,
      value = _ref2$value === void 0 ? undefined : _ref2$value,
      _ref2$fieldName = _ref2.fieldName,
      fieldName = _ref2$fieldName === void 0 ? undefined : _ref2$fieldName,
      _ref2$id = _ref2.id,
      id = _ref2$id === void 0 ? undefined : _ref2$id,
      _ref2$step = _ref2.step,
      step = _ref2$step === void 0 ? undefined : _ref2$step;

  return {
    isRFFWrap: (0, _addonKnobs.boolean)('isRFFWrap', isRFFWrap),
    label: (0, _addonKnobs.text)('label', label),
    value: (0, _addonKnobs.number)('value', value),
    id: (0, _addonKnobs.text)('id', id),
    fieldName: (0, _addonKnobs.text)('fieldName', fieldName),
    step: (0, _addonKnobs.number)('step', step)
  };
};

var onChange = function onChange(_ref3) {
  var value = _ref3.target.value;
  dispatch((0, _other.updateRange)(value));
  (0, _react2.forceReRender)();
};

(0, _react2.storiesOf)('Web|form/Range').add('Example', function () {
  return _react.default.createElement(_component.default, _extends({}, props({
    value: getState().other.formRange.value
  }), {
    onChange: onChange
  }));
}).add('Example with redux form', function () {
  return _react.default.createElement(RFWrap, null, _react.default.createElement(_component.default, _extends({}, props({
    value: getState().other.formRange.value,
    isRFFWrap: true
  }), {
    onChange: onChange
  })));
}, {
  info: 'redux-form lib, reduxForm() parent'
});