<script setup>
import { defineProps } from 'vue'

const props = defineProps({
  cover: {
    type: String,
    default: ''
  },
  title: {
    type: String,
    default: ''
  },
  createdTime: {
    type: String,
    default: ''
  },
  lastModifiedTime: {
    type: String,
    default: ''
  },
  isDraft: {
    type: Boolean,
    default: false
  }
})

// 测试函数，可以根据需求替换
function onEdit() {
  console.log('编辑')
}

function onPermission() {
  console.log('权限')
}
</script>

<template>
  <div class="work-piece">
    <!-- 左侧：博客封面 + 标题 -->
    <div class="piece-left">
      <img :src="cover" alt="封面" class="cover-image" />
      <div class="title-text">{{ title }}</div>
    </div>

    <!-- 右侧：时间和操作按钮 -->
    <div class="piece-right">
      <!-- 上方时间信息 -->
      <div class="times">
        <div>创建时间：{{ createdTime }}</div>
        <div>最后修改：{{ lastModifiedTime }}</div>
      </div>
      <!-- 下方操作 -->
      <div class="actions">
        <span class="action-btn" @click="onEdit">编辑</span>
        <!-- 草稿时不显示“权限” -->
        <span
            v-if="!isDraft"
            class="action-btn"
            @click="onPermission"
        >
          权限
        </span>
      </div>
    </div>
  </div>
</template>

<style scoped>
/* 容器：一条“横向卡片” */
.work-piece {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #24303f; /* 暗色稍微提亮 */
  border-radius: 6px;
  padding: 10px;
}

.theme-light .work-piece {
  background-color: #f2f2f2;
  color: black;
}



/* 左侧 */
.piece-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.cover-image {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
}
.title-text {
  font-size: 16px;
  font-weight: bold;
}

/* 右侧 */
.piece-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.times {
  opacity: 0.5;
  font-size: small;
  text-align: right;
}
.actions {
  display: flex;
  gap: 16px;
}
.action-btn {
  font-size: 14px;
  opacity: 0.6;
  cursor: pointer;
}
.action-btn:hover {
  opacity: 0.5;
}
</style>
