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';
export default function useStore() {
  return useLocalStore(function () {
    return {
      id: null,
      setUserId: function setUserId(id) {
        this.id = id;
      },

      get getUserId() {
        return this.id;
      },

      loadUser: function loadUser() {
        var _this = this;

        return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
          return regeneratorRuntime.wrap(function _callee$(_context) {
            while (1) {
              switch (_context.prev = _context.next) {
                case 0:
                  axios.get('iam/choerodon/v1/users/self').then(function (data) {
                    _this.setUserId(data.id);
                  });

                case 1:
                case "end":
                  return _context.stop();
              }
            }
          }, _callee);
        }))();
      },
      count: {
        closeCount: 0,
        mergeCount: 0,
        openCount: 0,
        totalCount: 0,
        auditCount: 0
      },
      setCount: function setCount(data) {
        this.count = data;
      },

      get getCount() {
        return this.count;
      },

      tabKey: 'opened',
      setTabKey: function setTabKey(key) {
        this.tabKey = key;
      },

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

      url: '',
      setUrl: function setUrl(data) {
        this.url = data;
      },
      isEmpty: false,
      setIsEmpty: function setIsEmpty(flag) {
        this.isEmpty = flag;
      },

      get getIsEmpty() {
        return this.isEmpty;
      },

      loadUrl: function loadUrl(projectId, appId) {
        var _this2 = this;

        return axios.get("/devops/v1/projects/".concat(projectId, "/app_service/").concat(appId, "/git/url")).then(function (data) {
          if (data && data.failed) {
            Choerodon.prompt(data.message);
          } else {
            _this2.setUrl(data);
          }
        });
      },

      get getUrl() {
        return this.url;
      },

      checkMerge: function checkMerge(projectId, appServiceId) {
        return axios.get("/devops/v1/projects/".concat(projectId, "/member-check/").concat(appServiceId, "?type=MERGE_REQUEST_CREATE"));
      }
    };
  });
}