import { useLocalStore } from 'mobx-react-lite';
import { axios } from '@choerodon/boot';
import { handlePromptError } from "../../../../../../utils";
export default function useStore() {
  return useLocalStore(function () {
    return {
      data: [],
      loading: false,
      isEmpty: false,
      setIsEmpty: function setIsEmpty(flag) {
        this.isEmpty = flag;
      },

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

      loadCodeQualityData: function loadCodeQualityData(projectId, appServiceId) {
        var _this = this;

        this.loading = true;
        return axios.get("/devops/v1/projects/".concat(projectId, "/app_service/").concat(appServiceId, "/sonarqube")).then(function (data) {
          _this.loading = false;

          if (!data || data && data.status === 204) {
            _this.setIsEmpty(true);
          } else {
            var res = handlePromptError(data);

            if (res) {
              _this.data = data;

              _this.setIsEmpty(false);
            }
          }
        });
      }
    };
  });
}