var _excluded = ["projectId"],
    _excluded2 = ["projectId", "clusterId"];

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 _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

import { useLocalStore } from 'mobx-react-lite';
import { axios } from '@choerodon/boot';
import { handlePromptError } from "../../../../utils";
export default function useStore() {
  return useLocalStore(function () {
    return {
      navBounds: {},
      setNavBounds: function setNavBounds(data) {
        this.navBounds = data;
      },

      get getNavBounds() {
        return this.navBounds;
      },

      responseData: '',
      setResponseData: function setResponseData(data) {
        this.responseData = data;
      },

      get getResponseData() {
        return this.responseData;
      },

      clusterDefaultTab: null,
      setClusterDefaultTab: function setClusterDefaultTab(data) {
        this.clusterDefaultTab = data;
      },

      get getClusterDefaultTab() {
        return this.clusterDefaultTab;
      },

      canCreate: false,

      get getCanCreate() {
        return this.canCreate;
      },

      setCanCreate: function setCanCreate(flag) {
        this.canCreate = flag;
      },
      checkClusterName: function checkClusterName(_ref) {
        var projectId = _ref.projectId,
            clusterName = _ref.clusterName;
        return axios.get("/devops/v1/projects/".concat(projectId, "/clusters/check_name?name=").concat(clusterName));
      },
      checkClusterCode: function checkClusterCode(_ref2) {
        var projectId = _ref2.projectId,
            clusterCode = _ref2.clusterCode;
        return axios.get("/devops/v1/projects/".concat(projectId, "/clusters/check_code?code=").concat(clusterCode));
      },
      createCluster: function createCluster(_ref3) {
        var projectId = _ref3.projectId,
            rest = _objectWithoutProperties(_ref3, _excluded);

        return axios.post("/devops/v1/projects/".concat(projectId, "/clusters"), JSON.stringify(rest));
      },
      updateCluster: function updateCluster(_ref4) {
        var projectId = _ref4.projectId,
            clusterId = _ref4.clusterId,
            rest = _objectWithoutProperties(_ref4, _excluded2);

        return axios.put("/devops/v1/projects/".concat(projectId, "/clusters/").concat(clusterId, "?"), JSON.stringify(rest));
      },
      deleteCluster: function deleteCluster(_ref5) {
        var projectId = _ref5.projectId,
            clusterId = _ref5.clusterId;
        return axios["delete"]("/devops/v1/projects/".concat(projectId, "/clusters/").concat(clusterId));
      },
      deleteCheck: function deleteCheck(projectId, clusterId) {
        return axios.get("/devops/v1/projects/".concat(projectId, "/clusters/").concat(clusterId, "/check_connect_envs_and_pv"));
      },
      checkCreate: function checkCreate(projectId) {
        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, "/clusters/check_enable_create"));

                case 3:
                  res = _context.sent;

                  _this.setCanCreate(handlePromptError(res));

                  _context.next = 10;
                  break;

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

                  _this.setCanCreate(false);

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