"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.updateRadioGroup = exports.updateRadio = exports.updateRange = void 0;

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var UPDATE_RANGE = 'UPDATE_RANGE';

var updateRange = function updateRange(value) {
  return {
    type: UPDATE_RANGE,
    value: value
  };
};

exports.updateRange = updateRange;
var UPDATE_RADIO = 'UPDATE_RADIO';

var updateRadio = function updateRadio() {
  return {
    type: UPDATE_RADIO
  };
};

exports.updateRadio = updateRadio;
var UPDATE_RADIO_GROUP = 'UPDATE_RADIO_GROUP';

var updateRadioGroup = function updateRadioGroup(name) {
  return {
    type: UPDATE_RADIO_GROUP,
    name: name
  };
};

exports.updateRadioGroup = updateRadioGroup;
var INITIAL_STATE = {
  formRange: {
    value: 10
  },
  formRadio: {
    checked: undefined
  },
  formRadioGroup: {
    male: undefined,
    female: undefined
  }
};

var _default = function _default() {
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INITIAL_STATE;
  var action = arguments.length > 1 ? arguments[1] : undefined;

  switch (action.type) {
    case UPDATE_RANGE:
      {
        return _objectSpread({}, state, {
          formRange: {
            value: action.value
          }
        });
      }

    case UPDATE_RADIO:
      {
        return _objectSpread({}, state, {
          formRadio: {
            checked: !state.formRadio.checked
          }
        });
      }

    case UPDATE_RADIO_GROUP:
      {
        return _objectSpread({}, state, {
          formRadioGroup: _defineProperty({
            male: false,
            female: false
          }, action.name, !state.formRadioGroup[action.name])
        });
      }

    default:
      return state;
  }
};

exports.default = _default;