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

import { useLocalStore } from 'mobx-react-lite';
import { axios, Choerodon } from '@choerodon/boot';
import { handlePromptError } from "../../../utils";
export default function useStore() {
  return useLocalStore(function () {
    return {
      appServiceLoading: false,
      setAppServiceLoading: function setAppServiceLoading(flag) {
        this.appServiceLoading = flag;
      },

      get getAppServiceLoading() {
        return this.appServiceLoading;
      },

      appService: [],
      setAppService: function setAppService(data) {
        this.appService = data;
      },

      get getAppService() {
        return this.appService.slice();
      },

      shareAppService: [],
      setShareAppService: function setShareAppService(data) {
        this.shareAppService = data;
      },

      get getShareAppService() {
        return this.shareAppService.slice();
      },

      configValue: '',
      setConfigValue: function setConfigValue(data) {
        this.configValue = data;
      },

      get getConfigValue() {
        return this.configValue;
      },

      certificates: [],
      setCertificates: function setCertificates(data) {
        this.certificates = data;
      },

      get getCertificates() {
        return this.certificates;
      },

      startPipeline: function startPipeline(projectId, pipelineIds) {
        return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
          var res;
          return regeneratorRuntime.wrap(function _callee$(_context) {
            while (1) {
              switch (_context.prev = _context.next) {
                case 0:
                  _context.prev = 0;
                  _context.next = 3;
                  return axios.get("/devops/v1/projects/".concat(projectId, "/pipeline/batch_execute?pipelineIds=").concat(pipelineIds));

                case 3:
                  res = _context.sent;
                  return _context.abrupt("return", handlePromptError(res));

                case 7:
                  _context.prev = 7;
                  _context.t0 = _context["catch"](0);
                  return _context.abrupt("return", false);

                case 10:
                case "end":
                  return _context.stop();
              }
            }
          }, _callee, null, [[0, 7]]);
        }))();
      },
      loadAppService: function loadAppService(projectId, type) {
        var _this = this;

        return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
          var res;
          return regeneratorRuntime.wrap(function _callee2$(_context2) {
            while (1) {
              switch (_context2.prev = _context2.next) {
                case 0:
                  _context2.prev = 0;

                  _this.setAppServiceLoading(true);

                  _context2.next = 4;
                  return axios.get("/devops/v1/projects/".concat(projectId, "/app_service/list_all_app_services?service_type=normal&deploy_only=true&type=").concat(type));

                case 4:
                  res = _context2.sent;

                  if (handlePromptError(res)) {
                    _this.setAppService(res);
                  }

                  _this.setAppServiceLoading(false);

                  _context2.next = 13;
                  break;

                case 9:
                  _context2.prev = 9;
                  _context2.t0 = _context2["catch"](0);

                  _this.setAppServiceLoading(false);

                  Choerodon.handleResponseError(_context2.t0);

                case 13:
                case "end":
                  return _context2.stop();
              }
            }
          }, _callee2, null, [[0, 9]]);
        }))();
      },
      loadShareAppService: function loadShareAppService(projectId) {
        var _this2 = this;

        return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
          var res;
          return regeneratorRuntime.wrap(function _callee3$(_context3) {
            while (1) {
              switch (_context3.prev = _context3.next) {
                case 0:
                  _context3.prev = 0;
                  _context3.next = 3;
                  return axios.get("/devops/v1/projects/".concat(projectId, "/app_service/list_all_app_services?service_type=normal&deploy_only=true&type=share_service"));

                case 3:
                  res = _context3.sent;

                  if (handlePromptError(res)) {
                    _this2.setShareAppService(res);
                  }

                  _context3.next = 10;
                  break;

                case 7:
                  _context3.prev = 7;
                  _context3.t0 = _context3["catch"](0);
                  Choerodon.handleResponseError(_context3.t0);

                case 10:
                case "end":
                  return _context3.stop();
              }
            }
          }, _callee3, null, [[0, 7]]);
        }))();
      },
      loadConfigValue: function loadConfigValue(projectId, id) {
        var _this3 = this;

        return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
          var res;
          return regeneratorRuntime.wrap(function _callee4$(_context4) {
            while (1) {
              switch (_context4.prev = _context4.next) {
                case 0:
                  _context4.prev = 0;
                  _context4.next = 3;
                  return axios.get("/devops/v1/projects/".concat(projectId, "/deploy_value?value_id=").concat(id));

                case 3:
                  res = _context4.sent;

                  if (!handlePromptError(res)) {
                    _context4.next = 7;
                    break;
                  }

                  _this3.setConfigValue(res.value);

                  return _context4.abrupt("return", res.value);

                case 7:
                  _context4.next = 12;
                  break;

                case 9:
                  _context4.prev = 9;
                  _context4.t0 = _context4["catch"](0);
                  Choerodon.handleResponseError(_context4.t0);

                case 12:
                case "end":
                  return _context4.stop();
              }
            }
          }, _callee4, null, [[0, 9]]);
        }))();
      },
      loadDeployValue: function loadDeployValue(projectId, id) {
        var _this4 = this;

        return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
          var res;
          return regeneratorRuntime.wrap(function _callee5$(_context5) {
            while (1) {
              switch (_context5.prev = _context5.next) {
                case 0:
                  _context5.prev = 0;
                  _context5.next = 3;
                  return axios.get("/devops/v1/projects/".concat(projectId, "/app_service_instances/deploy_value?version_id=").concat(id, "&type=create"));

                case 3:
                  res = _context5.sent;

                  if (!handlePromptError(res)) {
                    _context5.next = 7;
                    break;
                  }

                  _this4.setConfigValue(res.yaml);

                  return _context5.abrupt("return", res.yaml);

                case 7:
                  _context5.next = 12;
                  break;

                case 9:
                  _context5.prev = 9;
                  _context5.t0 = _context5["catch"](0);
                  Choerodon.handleResponseError(_context5.t0);

                case 12:
                case "end":
                  return _context5.stop();
              }
            }
          }, _callee5, null, [[0, 9]]);
        }))();
      },
      loadMarketDeployValue: function loadMarketDeployValue(projectId, id) {
        var _this5 = this;

        return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
          var res;
          return regeneratorRuntime.wrap(function _callee6$(_context6) {
            while (1) {
              switch (_context6.prev = _context6.next) {
                case 0:
                  _context6.prev = 0;
                  _context6.next = 3;
                  return axios.get("/market/v1/projects/".concat(projectId, "/deploy/values?deploy_object_id=").concat(id));

                case 3:
                  res = _context6.sent;

                  if (!handlePromptError(res)) {
                    _context6.next = 7;
                    break;
                  }

                  _this5.setConfigValue(res.value);

                  return _context6.abrupt("return", res.value);

                case 7:
                  _context6.next = 12;
                  break;

                case 9:
                  _context6.prev = 9;
                  _context6.t0 = _context6["catch"](0);
                  Choerodon.handleResponseError(_context6.t0);

                case 12:
                case "end":
                  return _context6.stop();
              }
            }
          }, _callee6, null, [[0, 9]]);
        }))();
      },
      checkNetWorkName: function checkNetWorkName(projectId, envId, value) {
        return axios.get("/devops/v1/projects/".concat(projectId, "/service/check_name?env_id=").concat(envId, "&name=").concat(value));
      },
      loadCertByEnv: function loadCertByEnv(projectId, envId, domain) {
        var _this6 = this;

        return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {
          var res;
          return regeneratorRuntime.wrap(function _callee7$(_context7) {
            while (1) {
              switch (_context7.prev = _context7.next) {
                case 0:
                  _context7.prev = 0;
                  _context7.next = 3;
                  return axios.post("/devops/v1/projects/".concat(projectId, "/certifications/active?env_id=").concat(envId, "&domain=").concat(domain));

                case 3:
                  res = _context7.sent;

                  if (handlePromptError(res)) {
                    _this6.setCertificates(res);
                  }

                  _context7.next = 10;
                  break;

                case 7:
                  _context7.prev = 7;
                  _context7.t0 = _context7["catch"](0);
                  Choerodon.handleResponseError(_context7.t0);

                case 10:
                case "end":
                  return _context7.stop();
              }
            }
          }, _callee7, null, [[0, 7]]);
        }))();
      },
      checkName: function checkName(projectId, value, envId) {
        return axios.get("/devops/v1/projects/".concat(projectId, "/ingress/check_name?env_id=").concat(envId, "&name=").concat(value));
      },
      checkPath: function checkPath(projectId, domain, env, value) {
        var id = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '';
        return axios.get("/devops/v1/projects/".concat(projectId, "/ingress/check_domain?domain=").concat(domain, "&env_id=").concat(env, "&path=").concat(value, "&id=").concat(id));
      }
    };
  });
}