<template>
  <div v-if="files.length" class="team-background-upload-queue">
    <div v-for="item in files" :key="item.id" class="queue-item">
      <div class="queue-item__main">
        <span class="queue-item__name" :title="item.name">{{ item.name }}</span>
        <span :class="['queue-item__status', `is-${item.status}`]">
          {{ statusLabels[item.status] || item.status }}
        </span>
      </div>
      <el-progress
        v-if="item.status === 'uploading'"
        :percentage="item.progress"
        :show-text="false"
      />
      <div v-if="item.error" class="queue-item__error">{{ item.error }}</div>
      <div class="queue-item__actions">
        <el-button
          v-if="item.status === 'failed'"
          type="text"
          size="mini"
          @click="$emit('retry', item)"
        >重试</el-button>
        <el-button
          v-if="item.status !== 'uploading'"
          type="text"
          size="mini"
          @click="$emit('remove', item)"
        >移除</el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TeamBackgroundUploadQueue',
  props: {
    files: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      statusLabels: {
        pending: '等待上传',
        uploading: '上传中',
        success: '上传成功',
        failed: '上传失败'
      }
    }
  }
}
</script>

<style scoped lang="scss">
.team-background-upload-queue {
  margin: 12px 0 18px;
}

.queue-item {
  position: relative;
  padding: 10px 104px 10px 12px;
  margin-top: 8px;
  background: #f7f8fa;
  border-radius: 4px;
}

.queue-item__main {
  display: flex;
  min-width: 0;
  align-items: center;
}

.queue-item__name {
  overflow: hidden;
  color: #303133;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-item__status {
  flex: none;
  margin-left: 12px;
  color: #909399;

  &.is-success {
    color: #67c23a;
  }

  &.is-failed {
    color: #f56c6c;
  }
}

.queue-item__error {
  margin-top: 6px;
  color: #f56c6c;
  font-size: 12px;
}

.queue-item__actions {
  position: absolute;
  top: 4px;
  right: 12px;
  white-space: nowrap;
}
</style>
