/* eslint-disable import/no-anonymous-default-export */
import { DataSet } from 'choerodon-ui/pro/lib';
import { get } from 'lodash';
export default (function (_ref) {
  var projectId = _ref.projectId,
      ReportsStore = _ref.ReportsStore,
      mainStore = _ref.mainStore;
  return {
    selection: 'single',
    autoQuery: true,
    paging: false,
    transport: {
      read: function read(_ref2) {
        var dataSet = _ref2.dataSet;
        return {
          url: "devops/v1/projects/".concat(projectId, "/cicd_pipelines/devops/pipeline"),
          method: 'get'
        };
      }
    },
    events: {
      load: function load(_ref3) {
        var dataSet = _ref3.dataSet;
        var ps = ['choerodon.code.project.deploy.app-deployment.pipeline.ps.create'];

        if (dataSet.length) {
          mainStore.setSelectedPipeline(get(dataSet.toData()[0], 'id'));
        } else {
          ReportsStore.judgeRole(ps);
        }
      }
    }
  };
});