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

      get getEnvData() {
        return this.envData.slice();
      },

      loadEnvData: function loadEnvData(projectId) {
        var _this = this;

        return axios.get("/devops/v1/projects/".concat(projectId, "/envs/list_by_active?active=true")).then(function (data) {
          if (handlePromptError(data)) {
            _this.setEnvData(data);
          }
        });
      },
      createVisible: false,
      setCreateVisible: function setCreateVisible(value) {
        this.createVisible = value;
      },
      eidtVisible: false,
      setEditVisible: function setEditVisible(value) {
        this.eidtVisible = value;
      },

      /**
       * 
       * @param {*} projectId 
       * @param {*} id 
       */
      checkExcecute: function checkExcecute(projectId, id) {
        return axios.get("/devops/v1/projects/".concat(projectId, "/pipeline/check_deploy?pipeline_id=").concat(id));
      },
      changeStatus: function changeStatus(projectId, id, status) {
        return axios.put("/devops/v1/projects/".concat(projectId, "/pipeline/").concat(id, "?isEnabled=").concat(status));
      },
      deletePipeline: function deletePipeline(projectId, id) {
        return axios["delete"]("/devops/v1/projects/".concat(projectId, "/pipeline/").concat(id));
      },
      executePipeline: function executePipeline(projectId, id) {
        return axios.get("/devops/v1/projects/".concat(projectId, "/pipeline/").concat(id, "/execute"));
      }
    };
  });
}