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

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

      queryBranchData: function queryBranchData(_ref) {
        var _this = this;

        var projectId = _ref.projectId,
            _ref$sorter = _ref.sorter,
            sorter = _ref$sorter === void 0 ? {
          field: 'createDate',
          order: 'asc'
        } : _ref$sorter,
            _ref$postData = _ref.postData,
            postData = _ref$postData === void 0 ? {
          searchParam: {},
          param: ''
        } : _ref$postData,
            _ref$size = _ref.size,
            size = _ref$size === void 0 ? 3 : _ref$size,
            appServiceId = _ref.appServiceId;
        axios.post("/devops/v1/projects/".concat(projectId, "/app_service/").concat(appServiceId, "/git/page_branch_by_options?page=1&size=").concat(size), JSON.stringify(postData)).then(function (data) {
          if (handlePromptError(data)) {
            _this.branchData = data.list || [];
            _this.branchTotal = data.total;
          }
        });
      },
      checkTagName: function checkTagName(projectId, name, appServiceId) {
        return axios.get("/devops/v1/projects/".concat(projectId, "/app_service/").concat(appServiceId, "/git/check_tag?tag_name=").concat(name));
      },
      deleteTag: function deleteTag(projectId, tag, appServiceId) {
        return axios["delete"]("/devops/v1/projects/".concat(projectId, "/app_service/").concat(appServiceId, "/git/tags?tag=").concat(tag));
      },
      editTag: function editTag(projectId, tag, release, appServiceId) {
        return axios.put("/devops/v1/projects/".concat(projectId, "/app_service/").concat(appServiceId, "/git/tags?tag=").concat(tag), release);
      },
      checkCreate: function checkCreate(projectId, appServiceId) {
        var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'TAG_CREATE';
        return axios.get("/devops/v1/projects/".concat(projectId, "/member-check/").concat(appServiceId, "?type=").concat(type));
      }
    };
  });
}