'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _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; };

var _tools = require('views/utils/tools');

var _lodash = require('lodash');

const initState = {
  api_max_num: 0,
  api_deck: {}
};

const reducer = (state = initState, action) => {
  const { type, body, postBody } = action;
  switch (type) {
    case '@@Response/kcsapi/api_get_member/preset_deck':
      return _extends({}, state, {
        api_max_num: body.api_max_num,
        api_deck: (0, _tools.compareUpdate)(state.api_deck, body.api_deck, 3)
      });
    case '@@Response/kcsapi/api_req_hensei/preset_register':
      {
        const { api_preset_no } = body;
        return _extends({}, state, {
          api_deck: (0, _tools.reduxSet)(state.api_deck, String(api_preset_no), body)
        });
      }
    case '@@Response/kcsapi/api_req_hensei/preset_delete':
      {
        const { api_preset_no } = postBody; // it's a String
        return _extends({}, state, {
          api_deck: (0, _lodash.omit)(state.api_deck, api_preset_no)
        });
      }
  }
  return state;
};

exports.default = reducer;
module.exports = exports['default'];