import { useLocalStore } from 'mobx-react-lite';
import { axios, Choerodon } from '@choerodon/boot';
import { handlePromptError } from "../../../utils";
export default function useStore(mainStore) {
  return useLocalStore(function () {
    return {
      detailData: {},
      loadDetail: function loadDetail(projectId, gitlabPipelineId) {
        return axios.get("devops/v1/projects/".concat(projectId, "/cicd_pipelines_record/details?record_rel_id=").concat(gitlabPipelineId));
      },
      loadDetailData: function loadDetailData(projectId, gitlabPipelineId) {
        var _this = this;

        this.setDetailLoading(true);
        this.loadDetail(projectId, gitlabPipelineId).then(function (res) {
          if (handlePromptError(res)) {
            var devopsPipelineRecordRelId = mainStore.getSelectedMenu.devopsPipelineRecordRelId;

            if (String(devopsPipelineRecordRelId) === String(gitlabPipelineId)) {
              _this.setDetailData(res);
            }

            _this.setDetailLoading(false);
          }
        })["catch"](function (e) {
          Choerodon.handleResponseError(e);
        });
      },
      setDetailData: function setDetailData(value) {
        this.detailData = value;
      },

      get getDetailData() {
        return this.detailData;
      },

      detailLoading: true,
      setDetailLoading: function setDetailLoading(value) {
        this.detailLoading = value;
      },

      get getDetailLoading() {
        return this.detailLoading;
      },

      retryJob: function retryJob(projectId, gitlabProjectId, jobId) {
        return axios.get("/devops/v1/projects/".concat(projectId, "/ci_jobs/gitlab_projects/").concat(gitlabProjectId, "/gitlab_jobs/").concat(jobId, "/retry"));
      },
      retryCdJob: function retryCdJob(projectId, pipelineRecordId) {
        return axios.get("devops/v1/projects/".concat(projectId, "/cicd_pipelines_record/retry_cd_task?cd_pipeline_record_id=").concat(pipelineRecordId));
      },
      executeCustomJob: function executeCustomJob(projectId, gitlabProjectId, jobId) {
        return axios.get("/devops/v1/projects/".concat(projectId, "/ci_jobs/gitlab_projects/").concat(gitlabProjectId, "/gitlab_jobs/").concat(jobId, "/play"));
      }
    };
  });
}