function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

import { useLocalStore } from 'mobx-react-lite';
import { axios, Choerodon } from '@choerodon/boot';
import { handlePromptError } from "../../../../../../../utils";
export default function useStore() {
  return useLocalStore(function () {
    return {
      logContentLoading: false,
      logData: [],
      setLogData: function setLogData(data) {
        this.logData = _toConsumableArray(data);
      },

      get getLogData() {
        var _this$logData;

        return (_this$logData = this.logData) === null || _this$logData === void 0 ? void 0 : _this$logData.slice();
      },

      loadDeployLogData: function loadDeployLogData(projectId, pipelineRecordId, stageRecordId, jobRecordsId) {
        var _this = this;

        return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
          var res;
          return regeneratorRuntime.wrap(function _callee$(_context) {
            while (1) {
              switch (_context.prev = _context.next) {
                case 0:
                  _this.logContentLoading = true;
                  _context.prev = 1;
                  _context.next = 4;
                  return axios.get("/devops/v1/projects/".concat(projectId, "/pipeline_records/").concat(pipelineRecordId, "/stage_records/").concat(stageRecordId, "/job_records/").concat(jobRecordsId, "/logs"));

                case 4:
                  res = _context.sent;
                  _this.logContentLoading = false;

                  _this.setLogData(res);

                  return _context.abrupt("return", handlePromptError(res));

                case 10:
                  _context.prev = 10;
                  _context.t0 = _context["catch"](1);
                  _this.logContentLoading = false;
                  Choerodon.handleResponseError(_context.t0);
                  return _context.abrupt("return", false);

                case 15:
                case "end":
                  return _context.stop();
              }
            }
          }, _callee, null, [[1, 10]]);
        }))();
      }
    };
  });
}