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(_ref) {
  var NODE_TAB = _ref.NODE_TAB;
  return useLocalStore(function () {
    return {
      tabKey: NODE_TAB,
      setTabKey: function setTabKey(data) {
        this.tabKey = data;
      },

      get getTabKey() {
        return this.tabKey;
      },

      grafanaUrl: null,
      setGrafanaUrl: function setGrafanaUrl(data) {
        this.grafanaUrl = data;
      },

      get getGrafanaUrl() {
        return this.grafanaUrl;
      },

      componentList: [],
      setComponentList: function setComponentList(data) {
        this.componentList = data;
      },

      get getComponentList() {
        return this.componentList;
      },

      prometheusStatus: [],
      setPrometheusStatus: function setPrometheusStatus(data) {
        this.prometheusStatus = data;
      },

      get getPrometheusStatus() {
        return this.prometheusStatus;
      },

      prometheusLoading: false,
      setPrometheusLoading: function setPrometheusLoading(data) {
        this.prometheusLoading = data;
      },

      get getPrometheusLoading() {
        return this.prometheusLoading;
      },

      hasEnv: false,
      setHasEnv: function setHasEnv(flag) {
        this.hasEnv = flag;
      },

      get getHasEnv() {
        return this.hasEnv;
      },

      polarisLoading: true,
      setPolarisLoading: function setPolarisLoading(flag) {
        this.polarisLoading = flag;
      },

      get getPolarisLoading() {
        return this.polarisLoading;
      },

      // eslint-disable-next-line consistent-return
      loadGrafanaUrl: function loadGrafanaUrl(projectId, clusterId) {
        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:
                  _context.prev = 0;
                  _context.next = 3;
                  return axios.get("/devops/v1/projects/".concat(projectId, "/cluster_resource/grafana_url?cluster_id=").concat(clusterId, "&type=cluster"));

                case 3:
                  res = _context.sent;

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

                  _this.setGrafanaUrl(res);

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

                case 7:
                  _this.setGrafanaUrl(null);

                  _context.next = 13;
                  break;

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

                case 13:
                case "end":
                  return _context.stop();
              }
            }
          }, _callee, null, [[0, 10]]);
        }))();
      },
      loadComponentList: function loadComponentList(projectId, clusterId) {
        var _this2 = 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;
                  _context2.next = 3;
                  return axios.get("/devops/v1/projects/".concat(projectId, "/cluster_resource?cluster_id=").concat(clusterId));

                case 3:
                  res = _context2.sent;

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

                  _context2.next = 10;
                  break;

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

                case 10:
                case "end":
                  return _context2.stop();
              }
            }
          }, _callee2, null, [[0, 7]]);
        }))();
      },
      installCertManager: function installCertManager(projectId, clusterId) {
        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.post("/devops/v1/projects/".concat(projectId, "/cluster_resource/cert_manager/deploy?cluster_id=").concat(clusterId));

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

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

                case 11:
                case "end":
                  return _context3.stop();
              }
            }
          }, _callee3, null, [[0, 7]]);
        }))();
      },
      checkUninstallCert: function checkUninstallCert(projectId, clusterId) {
        return axios.get("/devops/v1/projects/".concat(projectId, "/cluster_resource/cert_manager/check?cluster_id=").concat(clusterId));
      },
      uninstallCert: function uninstallCert(projectId, clusterId) {
        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["delete"]("/devops/v1/projects/".concat(projectId, "/cluster_resource/cert_manager/unload?cluster_id=").concat(clusterId));

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

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

                case 11:
                case "end":
                  return _context4.stop();
              }
            }
          }, _callee4, null, [[0, 7]]);
        }))();
      },
      uninstallMonitor: function uninstallMonitor(projectId, clusterId) {
        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["delete"]("/devops/v1/projects/".concat(projectId, "/cluster_resource/prometheus/unload?cluster_id=").concat(clusterId));

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

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

                case 11:
                case "end":
                  return _context5.stop();
              }
            }
          }, _callee5, null, [[0, 7]]);
        }))();
      },
      loadPrometheusStatus: function loadPrometheusStatus(projectId, clusterId) {
        var _this3 = 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:
                  _this3.setPrometheusLoading(true);

                  _context6.prev = 1;
                  _context6.next = 4;
                  return axios.get("/devops/v1/projects/".concat(projectId, "/cluster_resource/prometheus/deploy_status?cluster_id=").concat(clusterId));

                case 4:
                  res = _context6.sent;

                  if (handlePromptError(res)) {
                    _this3.setPrometheusStatus(res);
                  }

                  _this3.setPrometheusLoading(false);

                  _context6.next = 13;
                  break;

                case 9:
                  _context6.prev = 9;
                  _context6.t0 = _context6["catch"](1);

                  _this3.setPrometheusLoading(false);

                  Choerodon.handleResponseError(_context6.t0);

                case 13:
                case "end":
                  return _context6.stop();
              }
            }
          }, _callee6, null, [[1, 9]]);
        }))();
      },
      retryPrometheus: function retryPrometheus(projectId, clusterId) {
        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.get("/devops/v1/projects/".concat(projectId, "/cluster_resource/prometheus/retry?cluster_id=").concat(clusterId));

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

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

                case 10:
                case "end":
                  return _context7.stop();
              }
            }
          }, _callee7, null, [[0, 7]]);
        }))();
      },
      checkHasEnv: function checkHasEnv(projectId, clusterId) {
        var _this4 = this;

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

                  _this4.setPolarisLoading(true);

                  _context8.next = 4;
                  return axios.get("/devops/v1/projects/".concat(projectId, "/envs/count_by_options?cluster_id=").concat(clusterId));

                case 4:
                  res = _context8.sent;
                  result = handlePromptError(res);

                  _this4.setHasEnv(result);

                  _this4.setPolarisLoading(false);

                  return _context8.abrupt("return", result);

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

                  _this4.setPolarisLoading(false);

                  return _context8.abrupt("return", false);

                case 16:
                case "end":
                  return _context8.stop();
              }
            }
          }, _callee8, null, [[0, 11]]);
        }))();
      },
      ManualScan: function ManualScan(projectId, clusterId) {
        return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() {
          var res, result;
          return regeneratorRuntime.wrap(function _callee9$(_context9) {
            while (1) {
              switch (_context9.prev = _context9.next) {
                case 0:
                  _context9.prev = 0;
                  _context9.next = 3;
                  return axios.post("/devops/v1/projects/".concat(projectId, "/polaris/clusters/").concat(clusterId));

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

                case 8:
                  _context9.prev = 8;
                  _context9.t0 = _context9["catch"](0);
                  Choerodon.handleResponseError(_context9.t0);
                  return _context9.abrupt("return", false);

                case 12:
                case "end":
                  return _context9.stop();
              }
            }
          }, _callee9, null, [[0, 8]]);
        }))();
      },
      getDeleteRolePemissionUrl: function getDeleteRolePemissionUrl(projectId, nodeId, role) {
        return axios.get("devops/v1/projects/".concat(projectId, "/nodes/").concat(nodeId, "/roles/").concat(role, "/check_enable_delete"));
      },
      deleteNode: function deleteNode(projectId, nodeId) {
        return axios["delete"]("devops/v1/projects/".concat(projectId, "/nodes/").concat(nodeId));
      },
      handleNodeIdDelele: function handleNodeIdDelele(projectId, id) {
        return axios.get("/devops/v1/projects/".concat(projectId, "/nodes/check_operating_result?operationRecordId=").concat(id));
      },
      removeRole: function removeRole(projectId, nodeId, role) {
        return axios["delete"]("devops/v1/projects/".concat(projectId, "/nodes/").concat(nodeId, "/roles/").concat(role));
      }
    };
  });
}