<template>
	<s-layout title="内容详情">
		<!-- 顶部区域：作者 + 按钮 -->
		<view class="top-bar">
			<text class="author-name">{{ detail.nickname || '未知作者' }}</text>
			<view class="actions">
				<button class="action-btn" @click="follow">关注</button>
				<button class="action-btn" open-type="share">分享</button>
			</view>
		</view>

		<!-- 内容图片 -->
		<view class="detail-container">
			<image :src="detail.picUrl" class="detail-img" mode="widthFix" />
		</view>

		<!-- 评论区 -->
		<view class="comments-section">
			<view class="comment-item" v-for="(comment, index) in comments" :key="index">
				<text class="comment-author">{{ comment.user }}</text>
				<text class="comment-content">{{ comment.content }}</text>
			</view>
		</view>

		<!-- 底部评论输入框 -->
		<view class="comment-bar" @click="showInput = true">
			<text class="comment-placeholder">写评论...</text>
		</view>

		<!-- 弹出的真正输入框 -->
		<view class="input-popup" v-if="showInput">
			<input v-model="newComment" class="real-input" placeholder="请输入评论" confirm-type="send"
				@confirm="submitComment" @blur="showInput = false" />
		</view>
	</s-layout>
</template>

<script>
	import SeedApi from '@/sheep/api/seedComm/seedComm.js';

	export default {
		data() {
			return {
				detail: {},
				comments: [],
				newComment: '',
				showInput: false
			};
		},
		onLoad(options) {
			const id = options.id;
			this.getDetail(id);
			this.getComments(id);
		},
		methods: {
			getDetail(id) {
				SeedApi.getById({
					id
				}).then(res => {
					this.detail = res.data;
				}).catch(console.error);
			},
			getComments(id) {
				// 模拟评论获取，替换为你的接口
				this.comments = [{
						user: '用户A',
						content: '不错的内容～'
					},
					{
						user: '用户B',
						content: '很喜欢这张图！'
					}
				];
			},
			follow() {
				uni.showToast({
					title: '已关注',
					icon: 'success'
				});
			},
			submitComment() {
				if (!this.newComment.trim()) return;
				this.comments.push({
					user: '我',
					content: this.newComment
				});
				this.newComment = '';
				this.showInput = false;
			}
		}
	};
</script>

<style scoped>
	.top-bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 24rpx 30rpx;
		background-color: #fff;
		border-bottom: 1px solid #eee;
	}

	.author-name {
		font-size: 32rpx;
		font-weight: bold;
	}

	.actions {
		display: flex;
		gap: 20rpx;
	}

	.action-btn {
		font-size: 28rpx;
		padding: 10rpx 20rpx;
		border-radius: 10rpx;
		background-color: #f1f1f1;
	}

	.detail-container {
		padding: 30rpx;
		background-color: #fff;
	}

	.detail-img {
		width: 100%;
		border-radius: 20rpx;
	}

	.comments-section {
		padding: 20rpx 30rpx;
		background-color: #fff;
	}

	.comment-item {
		margin-bottom: 20rpx;
		border-bottom: 1px solid #f0f0f0;
		padding-bottom: 10rpx;
	}

	.comment-author {
		font-weight: bold;
		font-size: 28rpx;
	}

	.comment-content {
		display: block;
		font-size: 28rpx;
		color: #333;
		margin-top: 6rpx;
	}

	.comment-bar {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 100rpx;
		background-color: #f8f8f8;
		border-top: 1px solid #ddd;
		display: flex;
		align-items: center;
		padding: 0 30rpx;
		box-sizing: border-box;
	}

	.comment-placeholder {
		color: #999;
		font-size: 30rpx;
	}

	.input-popup {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		background-color: #fff;
		padding: 20rpx 30rpx;
		box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.1);
	}

	.real-input {
		width: 100%;
		height: 80rpx;
		border: 1px solid #ddd;
		border-radius: 12rpx;
		padding: 0 20rpx;
		font-size: 30rpx;
		box-sizing: border-box;
	}
</style>