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';
var NO_HEADER = [];
export default function useStore() {
  return useLocalStore(function () {
    return {
      selectedMenu: {},
      viewType: 'instance',
      noHeader: true,
      setSelectedMenu: function setSelectedMenu(data) {
        this.selectedMenu = data;
        this.noHeader = NO_HEADER.includes(menuType);
        var menuType = data.menuType;
      },

      get getSelectedMenu() {
        return this.selectedMenu;
      },

      changeViewType: function changeViewType(data) {
        this.viewType = data;
      },

      get getViewType() {
        return this.viewType;
      },

      setNoHeader: function setNoHeader(data) {
        this.noHeader = data;
      },

      get getNoHeader() {
        return this.noHeader;
      },

      loading: true,
      setLoading: function setLoading(data) {
        this.loading = data;
      },

      get getLoading() {
        return this.loading;
      },

      hasApp: true,
      setHasApp: function setHasApp(data) {
        this.hasApp = data;
      },

      get getHasApp() {
        return this.hasApp;
      },

      handleEncrept: function handleEncrept(urlAppServiceId, callback) {
        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.post('/devops/v1/encrypt', JSON.stringify([urlAppServiceId]));

                case 3:
                  res = _context.sent;

                  if (!(res && res.failed)) {
                    _context.next = 6;
                    break;
                  }

                  return _context.abrupt("return");

                case 6:
                  if (typeof res === 'object' && Object.prototype.hasOwnProperty.call(res, urlAppServiceId)) {
                    callback(res[urlAppServiceId]);
                  }

                  _context.next = 12;
                  break;

                case 9:
                  _context.prev = 9;
                  _context.t0 = _context["catch"](0);
                  throw new Error(_context.t0);

                case 12:
                case "end":
                  return _context.stop();
              }
            }
          }, _callee, null, [[0, 9]]);
        }))();
      },
      checkHasApp: function checkHasApp(projectId) {
        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:
                  _this.setLoading(true);

                  _context2.prev = 1;
                  _context2.next = 4;
                  return axios.get("/devops/v1/projects/".concat(projectId, "/app_service/count_by_active"));

                case 4:
                  res = _context2.sent;

                  if (res && !res.failed || res === 0) {
                    _this.setHasApp(res);
                  }

                  _this.setLoading(false);

                  _context2.next = 13;
                  break;

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

                  _this.setLoading(false);

                  Choerodon.handleResponseError(_context2.t0);

                case 13:
                case "end":
                  return _context2.stop();
              }
            }
          }, _callee2, null, [[1, 9]]);
        }))();
      }
    };
  });
}