<template>
	<view class="book-item" :class="{'horizontal': horizontal}" @click="$emit('click')">
		<view class="cover-wrapper">
			<image class="book-cover" :src="book.image
			&& book.image.split(',')[0]" mode="aspectFill"></image>
			<view class="tag original" v-if="book.isOriginal == 'Y'">原创</view>
		</view>
		<view class="book-info">
			<view class="book-title">{{book.name}}</view>
			<view class="book-author" v-if="!horizontal">{{book.author || '暂无作者昵称'}}</view>
			<view class="book-desc" v-if="!horizontal">{{book.details || '暂无简介'}}</view>
            
			<!-- <view class="content-row" v-if="!horizontal">
                <view class="book-tags" v-if="book.tags && book.tags.length">
                    <text class="tag" v-for="(tag, index) in book.tags" :key="index">{{tag}}</text>
                </view>
            </view> -->

            <view class="content-row" v-if="!horizontal">
				<bookStatus :status="book.status"/>
                <view class="book-text">
                    {{ item.service || '大家都在读' }}
                </view>
            </view>
		</view>
	</view>
</template>

<script>
	import bookStatus from './bookStatus.vue';
	export default {
		components : {
			bookStatus,
		},
		props: {
			book: {
				type: Object,
				default: {}
			},
			// 是否显示为水平布局（默认垂直布局）
			horizontal: {
				type: Boolean,
				default: false
			},
		},
		computed: {
			statusClass() {
				const statusMap = {
					'draft': 'new',
					'0': 'ongoing',
					'1': 'completed'
				};
				return statusMap[this.book.status] || 'ongoing';
			},
			statusText() {
				const textMap = {
					// '0': '新建',
					'0': '连载中',
					'1': '已完结'
				};
				return textMap[this.book.status] || '连载中';
			},
		},
		data() {
			return {}
		},
		methods: {
		}
	}
</script>

<style lang="scss" scoped>
.book-item {
	display: flex;
	padding: 20rpx 0;
	border-bottom: 1px solid #eee;
	
	&:last-child {
		border-bottom: none;
	}
	
	.cover-wrapper {
		position: relative;
		width: 150rpx;
		height: 196rpx;
		border-radius: 16rpx;
		margin-right: 20rpx;
		box-shadow: 0 4rpx 8rpx rgba(0,0,0,0.1);
	}
	
	.book-cover {
		width: 100%;
		height: 100%;
		border-radius: 16rpx;
	}
	
	.tag {
		position: absolute;
		top: 0;
		left: 0;
		font-size: 20rpx;
		color: #fff;
		padding: 2rpx 8rpx;
		
		&.original {
			background-color: #ffa502;
		}
	}
	
	.book-info {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		
		.book-title {
			font-size: 28rpx;
			font-weight: bold;
			color: #333;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			margin-bottom: 6rpx;
		}
		
		.book-author {
			font-size: 24rpx;
			color: #999;
			margin-bottom: 6rpx;
			flex: 1;
		}
		
		.book-desc {
			font-size: 24rpx;
			color: #999;
			line-height: 1.5;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 2;
			overflow: hidden;
			margin-bottom: 6rpx;
		}
		
		.content-row {
			display: flex;
			align-items: center;
			margin-bottom: 6rpx;
		}
		
		.book-tags {
			display: flex;
			flex-wrap: wrap;
			
			.tag {
				font-size: 20rpx;
				color: #666;
				background-color: #f5f5f5;
				padding: 4rpx 12rpx;
				border-radius: 20rpx;
				margin-right: 10rpx;
			}
		}
        .book-text{
            font-size: 20rpx;
        }
	}
}

/* 水平布局样式 - 用于网格展示 */
.book-item.horizontal {
	flex-direction: column;
	width: 160rpx;
	padding: 10rpx;
	border: none;
	
	.cover-wrapper {
		width: 100%;
		height: 200rpx;
		margin-right: 0;
		margin-bottom: 10rpx;
		position: relative;
	}
	
	.book-cover {
		width: 100%;
		height: 100%;
		border-radius: 16rpx;
	}
	
	.tag {
		position: absolute;
		top: 0;
		left: 0;
		font-size: 20rpx;
		color: #fff;
		padding: 2rpx 8rpx;
		
		&.original {
			background-color: #ffa502;
		}
	}
	
	.book-info {
		.title-row {
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
		
		.book-title {
			font-size: 26rpx;
			white-space: wrap;
			overflow: hidden;
			text-overflow: ellipsis;
			flex: 1;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 2;
			margin-right: 5rpx;
		}
		
		.book-author {
			font-size: 22rpx;
		}
		
		.book-desc {
			display: none;
		}
		
		.book-tags {
			display: none;
		}
	}
}
</style>
