<template>
  <div class="moments-view" :class="{ 'dark': themeStore.isDarkMode }">
    <div class="moments-content">
      <h1 class="page-title">朋友圈</h1>

      <!-- 发布动态 -->
      <div class="post-composer">
        <div class="composer-header">
          <div class="user-avatar" :style="{ background: userStore.currentUser?.color }">
            {{ userStore.currentUser?.nick_name?.charAt(0) }}
          </div>
          <CustomTextarea
            v-model="newPostContent"
            placeholder="分享新鲜事..."
            class="post-input"
            :rows="3"
          />
        </div>
        <div class="composer-actions">
          <div class="media-buttons">
            <button class="media-btn">
              <i class="fas fa-image"></i>
              图片
            </button>
            <button class="media-btn">
              <i class="fas fa-video"></i>
              视频
            </button>
          </div>
          <button class="publish-btn" :disabled="!newPostContent.trim()">
            发布
          </button>
        </div>
      </div>

      <!-- 动态列表 -->
      <div class="moments-list">
        <div
          v-for="moment in mockMoments"
          :key="moment.id"
          class="moment-card"
        >
          <div class="moment-header">
            <div class="author-avatar" :style="{ background: moment.author.color }">
              {{ moment.author.nick_name.charAt(0) }}
            </div>
            <div class="author-info">
              <h4 class="author-name">{{ moment.author.nick_name }}</h4>
              <p class="post-time">{{ moment.time }}</p>
            </div>
          </div>

          <div class="moment-content">
            <p class="moment-text">{{ moment.content }}</p>
            <div v-if="moment.images" class="moment-images">
              <img
                v-for="(image, index) in moment.images"
                :key="index"
                :src="image"
                :alt="`图片${index + 1}`"
                class="moment-image"
              />
            </div>
          </div>

          <div class="moment-actions">
            <button class="action-btn like-btn">
              <i class="fas fa-heart"></i>
              {{ moment.likes }}
            </button>
            <button class="action-btn comment-btn">
              <i class="fas fa-comment"></i>
              {{ moment.comments }}
            </button>
            <button class="action-btn share-btn">
              <i class="fas fa-share"></i>
              分享
            </button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import {ref} from 'vue';
import {useUserStore} from '../stores/user.ts';
import {useThemeStore} from '../stores/theme.ts';
import CustomTextarea from './CustomTextarea.vue';

const userStore = useUserStore();
const themeStore = useThemeStore();

const newPostContent = ref('');

const mockMoments = ref([
  {
    id: 1,
    author: {
      name: '张三',
      color: '#ff6b6b'
    },
    content: '今天天气真不错，出去走走心情都变好了！',
    time: '2小时前',
    likes: 12,
    comments: 3,
    images: ['/placeholder.svg?height=200&width=200']
  },
  {
    id: 2,
    author: {
      name: '李四',
      color: '#4ecdc4'
    },
    content: '刚完成了一个新项目，感觉很有成就感！',
    time: '5小时前',
    likes: 8,
    comments: 2
  },
  {
    id: 3,
    author: {
      name: '王五',
      color: '#45b7d1'
    },
    content: '分享一张美丽的日落照片',
    time: '1天前',
    likes: 25,
    comments: 7,
    images: ['/placeholder.svg?height=300&width=400']
  }
]);
</script>

<style scoped>
.moments-view {
  height: 100%;
  background: #f8fafc;
  overflow-y: auto;
}

.moments-view.dark {
  background: #111827;
}

.moments-content {
  padding: 24px;
  max-width: 600px;
  margin: 0 auto;
}

.page-title {
  font-size: 28px;
  font-weight: 700;
  color: #1a202c;
  margin-bottom: 24px;
  text-align: center;
}

.moments-view.dark .page-title {
  color: #f7fafc;
}

.post-composer {
  background: white;
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  border: 1px solid #e2e8f0;
}

.moments-view.dark .post-composer {
  background: #374151;
  border-color: #4b5563;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.composer-header {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  font-size: 16px;
  flex-shrink: 0;
}

.post-input {
  flex: 1;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.media-buttons {
  display: flex;
  gap: 12px;
}

.media-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  color: #64748b;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.media-btn:hover {
  background: #e2e8f0;
  color: #475569;
}

.moments-view.dark .media-btn {
  background: #4b5563;
  border-color: #6b7280;
  color: #d1d5db;
}

.moments-view.dark .media-btn:hover {
  background: #6b7280;
  color: #f3f4f6;
}

.publish-btn {
  padding: 8px 20px;
  background: linear-gradient(135deg, #4361ee, #3f37c9);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.publish-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(67, 97, 238, 0.3);
}

.publish-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.moments-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.moment-card {
  background: white;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  border: 1px solid #e2e8f0;
  transition: all 0.3s ease;
}

.moment-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.moments-view.dark .moment-card {
  background: #374151;
  border-color: #4b5563;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.moments-view.dark .moment-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.moment-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.author-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  font-size: 16px;
}

.author-info {
  flex: 1;
}

.author-name {
  font-size: 16px;
  font-weight: 600;
  color: #1a202c;
  margin: 0 0 4px 0;
}

.moments-view.dark .author-name {
  color: #f7fafc;
}

.post-time {
  font-size: 12px;
  color: #64748b;
  margin: 0;
}

.moments-view.dark .post-time {
  color: #9ca3af;
}

.moment-content {
  margin-bottom: 16px;
}

.moment-text {
  font-size: 14px;
  color: #374151;
  line-height: 1.6;
  margin: 0 0 12px 0;
}

.moments-view.dark .moment-text {
  color: #d1d5db;
}

.moment-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.moment-image {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.moment-image:hover {
  transform: scale(1.02);
}

.moment-actions {
  display: flex;
  gap: 20px;
  padding-top: 16px;
  border-top: 1px solid #e2e8f0;
}

.moments-view.dark .moment-actions {
  border-top-color: #4b5563;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.action-btn:hover {
  background: #f1f5f9;
  color: #475569;
}

.moments-view.dark .action-btn {
  color: #9ca3af;
}

.moments-view.dark .action-btn:hover {
  background: #4b5563;
  color: #d1d5db;
}

.like-btn:hover {
  color: #ef4444;
}

.comment-btn:hover {
  color: #3b82f6;
}

.share-btn:hover {
  color: #10b981;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .moments-content {
    padding: 16px;
  }

  .composer-actions {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }

  .media-buttons {
    justify-content: center;
  }

  .moment-images {
    grid-template-columns: 1fr;
  }
}
</style>
