"use strict";

exports.__esModule = true;
exports.default = void 0;
var _immutable = _interopRequireDefault(require("immutable"));
var _utils = require("../utils");
var _tasks = require("../actions/tasks");
var _propertyHelper = require("../utils/propertyHelper");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
(function () {
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
  enterModule && enterModule(module);
})();
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};
var initialState = _immutable.default.fromJS({
  tasks: [],
  taskInfos: {},
  logs: {}
});
var tasks = function tasks(state, action) {
  var _action$payload;
  if (state === void 0) {
    state = initialState;
  }
  switch (action.type) {
    case _tasks.GET_TASKINFO_SUCCESS:
      return state.setIn(["taskInfos", action.payload.taskId], _immutable.default.fromJS(action.payload));
    case _tasks.GET_TASK_LIST_SUCCESS:
      return state.set("tasks", _immutable.default.fromJS(action.payload.sort(function (a, b) {
        return (0, _propertyHelper.compareObjectProperty)(a, b, "created");
      })));
    case _tasks.DELETE_TASK_REQUEST:
      var deleteTaskId = (0, _utils.safeGet)(action, "meta", "taskId");
      return state.withMutations(function (s) {
        s.set("tasks", s.get("tasks").filter(function (task) {
          return task.get("taskId") !== deleteTaskId;
        }));
        s.deleteIn(["logs", deleteTaskId]);
        s.deleteIn(["taskInfos", deleteTaskId]);
      });
    case _tasks.GET_TASK_LOG_SUCCESS:
      var logTaskId = (0, _utils.safeGet)(action, "meta", "taskId");
      if (((_action$payload = action.payload) == null ? void 0 : _action$payload.length) > 0) {
        return state.setIn(["logs", logTaskId], _immutable.default.fromJS(action.payload.sort(function (a, b) {
          return (0, _propertyHelper.compareObjectProperty)(a, b, "executionTime");
        })));
      } else {
        return state.deleteIn(["logs", logTaskId]);
      }
    case _tasks.CLEAR_TASK_LOG:
      var taskId = (0, _utils.safeGet)(action, "meta", "taskId");
      return state.deleteIn(["logs", taskId]);
    default:
      return state;
  }
};
var _default = tasks;
var _default2 = _default;
var _default3 = exports.default = _default2;
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(initialState, "initialState", "/home/vsts/work/1/s/src/reducers/tasks.js");
  reactHotLoader.register(tasks, "tasks", "/home/vsts/work/1/s/src/reducers/tasks.js");
  reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/reducers/tasks.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();
;
(function () {
  var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
  if (!reactHotLoader) {
    return;
  }
  reactHotLoader.register(initialState, "initialState", "/home/vsts/work/1/s/src/reducers/tasks.js");
  reactHotLoader.register(tasks, "tasks", "/home/vsts/work/1/s/src/reducers/tasks.js");
  reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/reducers/tasks.js");
})();
;
(function () {
  var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
  leaveModule && leaveModule(module);
})();