<template>
  <el-card class="project-long-card" shadow="hover" @click="toDevcloud">
    <div style="display:flex;justify-content: space-between;align-items: center">
      <div v-if="project.name">
        <span class="project-long-card-name">名称：{{ project.name }}</span>
      </div>
      <div v-else>
        <span>项目ID：{{ project.id }}</span>
      </div>
      <div v-if="project.name">
        <span>成员：
          <span v-for="item in members" :key="'project'+project.id+'member'+item.id"
                class="project-long-card-member">{{ item.username }}
          </span>
          <span v-if="members.length===0">无权限查看</span>
        </span>
      </div>
      <el-button v-if="isTeacher" size="small" type="primary"
                 @click.stop="$emit('switch')">
        设为{{ isPublic ? "私有" : "公共" }}
      </el-button>
      <el-button v-if="isPublic&&!isTeacher" size="small" type="primary"
                 @click.stop="$emit('fork')">
        Fork
      </el-button>
    </div>
    <el-divider v-if="project.name"/>
    <div v-if="project.name">描述：{{ project.description }}</div>
    <div v-if="project.name">
      <span>链接：{{ GitURL }}</span>
      <i class="el-icon-document-copy" @click.stop="copyGitUrl"></i>
    </div>
  </el-card>
</template>

<script>

export default {
  name: "ProjectLongCard",
  props: {
    project: {
      type: Object,
      required: true,
    },
    isPublic: {
      type: Boolean,
      default: false,
    },
    isTeacher: {
      type: Boolean,
      default: false,
    }
  },
  emits: ["switch", "fork"],
  data() {
    return {
      members: [],
    };
  },
  computed:{
    GitURL(){
      let list = this.project.gitRemoteUrl.split("/");
      list[2] = "gitlab.internal-paas.seec.seecoder.cn";
      return list.join("/");
    }
  },
  async mounted() {
    console.log(this.GitURL);
    const _this = this;
    const res = (await _this.$apis.findProjectMembers(_this.project.id)).data;
    if (!res.code) {
      _this.members = res.data;
    }
  },
  methods: {
    toDevcloud() {
      if (this.members.length !== 0) {
        window.open("https://developer.internal-paas.seec.seecoder.cn/project/" + this.project.id + "/schedule?id_token=" + this.$store.state.user.token);
      }else{
        this.$message.info("无权限查看!");
      }
    },
    async copyGitUrl() {
      await navigator.clipboard.writeText(this.GitURL);
      this.$message.success("复制成功！");
    },
  },
};
</script>

<style scoped>
.project-long-card {
  margin-bottom: 10px;
  cursor: pointer;
}

.el-divider {
  margin: 2px;
}

.project-long-card-member {
  margin-right: 5px;
}

.project-long-card-member:hover {
  /*color: #409EFF;*/
}

.el-icon-document-copy {
  margin-left: 10px;
}

.el-icon-document-copy:hover {
  color: #409EFF;
}
</style>