<template>
  <el-card class="project-long-card" shadow="hover">
    <div style="display:flex;justify-content: space-between;align-items: center">
      <div v-if="project.name">
        <span>名称：{{ 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>
      </div>
      <el-button v-if="isTeacher" size="small" type="primary"
                 @click="$emit('switch')">
        设为{{ isPublic ? '私有' : '公共' }}
      </el-button>
      <el-button v-if="isPublic&&!isTeacher" size="small" type="primary"
                 @click="$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">链接：{{ project.gitRemoteUrl }}</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: [],
    };
  },
  async mounted() {
    const _this = this;
    const res = (await _this.$apis.findProjectMembers(_this.project.id)).data;
    if (!res.code) {
      _this.members = res.data;
    }
  },
};
</script>

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

.el-divider {
  margin: 2px;
}

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

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