<template>
  <div class="article-item" :class="{ 'has-image': showImage && article.image }">
    <NuxtLink :to="article.link || `/article/${article.id}`" class="article-link">
      <div class="article-content">
        <div class="article-title">{{ article.title }}</div>
        <div class="article-meta">
          <span v-if="article.source" class="source">{{ article.source }}</span>
          <span class="date">{{ article.date }}</span>
        </div>
      </div>
      <img v-if="showImage && article.image" :src="article.image" :alt="article.title" class="article-image" />
    </NuxtLink>
  </div>
</template>

<script setup lang="ts">
interface Article {
  id: number
  title: string
  date: string
  source?: string
  image?: string
  link?: string
}

defineProps<{
  article: Article
  showImage?: boolean
}>()
</script>

<style scoped>
.article-item {
  padding: 10px 0;
  border-bottom: 1px dashed #eee;
}

.article-item:last-child {
  border-bottom: none;
}

.article-link {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.article-content {
  flex: 1;
  min-width: 0;
}

.article-title {
  font-size: 14px;
  color: #333;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  transition: color 0.2s;
}

.article-link:hover .article-title {
  color: #1e3a5f;
}

.article-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  font-size: 12px;
  color: #999;
}

.source {
  color: #e74c3c;
}

.article-image {
  width: 100px;
  height: 70px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.has-image .article-title {
  -webkit-line-clamp: 1;
}

@media (max-width: 576px) {
  .article-image {
    width: 80px;
    height: 56px;
  }
}
</style>
