'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; };

exports.reducer = reducer;

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

// Preserved fields: api_id, api_member_id
const emptyRepair = {
  api_complete_time: 0,
  api_complete_time_str: '0',
  api_item1: 0,
  api_item2: 0,
  api_item3: 0,
  api_item4: 0,
  api_ship_id: 0,
  api_state: 0
};

function reducer(state = [], { type, body, postBody }) {
  switch (type) {
    case '@@Response/kcsapi/api_get_member/ndock':
      return (0, _tools.compareUpdate)(state, body);
    case '@@Response/kcsapi/api_port/port':
      return (0, _tools.compareUpdate)(state, body.api_ndock);
    case '@@Response/kcsapi/api_req_nyukyo/speedchange':
      {
        const { api_ndock_id } = postBody;
        state = state.slice();
        state[api_ndock_id - 1] = _extends({}, state[api_ndock_id - 1], emptyRepair);
        state;
      }
  }
  return state;
}