<template>
    <div class="sample-collection-page">
        <div class="card-grid">
            <!-- 卡片列表 -->
            <div v-for="(card, index) in cards" :key="index" class="card"
                :class="{ 'card-active': activeCardIndex === index }" @touchstart="handleTouchStart(index)"
                @touchend="handleTouchEnd(index)" @click="handleCardClick(card)">

                <div class="card-image-container">
                    <van-swipe :autoplay="3000">
                        <van-swipe-item v-for="(image, imgIndex) in card.images" :key="imgIndex">
                            <van-image :src="image" lazy-load>
                                <template v-slot:loading>
                                    <van-loading type="spinner" size="20" />
                                </template>
                            </van-image>
                        </van-swipe-item>
                    </van-swipe>
                    <div v-if="card.tag" class="card-tag" :style="card.tagStyle">
                        {{ card.tag }}
                    </div>
                </div>

                <div class="card-content">
                    <h2 class="card-title">{{ card.title }}</h2>
                    <p class="card-description">{{ card.description }}</p>

                    <div class="card-footer">
                        <div class="employee">
                            <van-tag round type="primary" v-for="employee in card.employee.split('&&')"
                                :key="employee">{{ employee
                                }}</van-tag>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'SampleCollectionPage',
    components: {},
    props: {},
    data() {

        return {
            cards: [
                {
                    title: "探索自然之美",
                    description: "深入原始森林，感受大自然的鬼斧神工。这里有清澈的溪流、茂密的树木和各种珍稀野生动物。",
                    images: ["https://picsum.photos/seed/card1/600/800", "https://picsum.photos/seed/card2/600/800"],

                    tag: "热门",
                    tagStyle: {
                        backgroundColor: "#F97316",
                        color: "#fff"
                    },
                    status: 0,
                    employee: "小吕&&寒冰射手",
                    neddTime: 2.0
                }
            ],
            activeCardIndex: -1
        };
    },
    watch: {},
    computed: {

    },
    methods: {
        handleTouchStart(index) {
            this.activeCardIndex = index;
        },

        handleTouchEnd() {
            setTimeout(() => {
                this.activeCardIndex = -1;
            }, 300);
        },

        handleCardClick(card) {
            console.log('点击了卡片:', card.title);
        },

        handleButtonClick(card) {
            console.log('点击了了解更多:', card.title);
        },


    },
    mounted() {
        // 处理按钮触摸反馈
        const buttons = document.querySelectorAll('.card-button');
        buttons.forEach(button => {
            button.addEventListener('touchstart', () => {
                button.classList.add('button-active');
            });

            button.addEventListener('touchend', () => {
                setTimeout(() => {
                    button.classList.remove('button-active');
                }, 200);
            });
        });
    },
    created() { },

};
</script>
<style lang="less" scoped>
// 变量定义
@base-bg: #f9fafb;
@card-bg: white;
@text-primary: #1f2937;
@text-secondary: #6b7280;
@accent-color: #3b82f6;
@accent-dark: #2563eb;
@danger-color: #ef4444;
@gray-light: #d1d5db;
@shadow-base: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
@shadow-active: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

// 基础样式
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, sans-serif;
}

body {
    background-color: @base-bg;
    min-height: 100vh;
    padding: 20px 0;
}

// 容器样式
.sample-collection-page {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 20px;

    .page-title {
        font-size: clamp(1.5rem, 3vw, 2rem);
        font-weight: bold;
        color: @text-primary;
        margin-bottom: 32px;
        text-align: center;
    }

    // 卡片网格布局
    .card-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 24px;

        // 移动端适配
        @media (max-width: 600px) {
            grid-template-columns: 1fr;
        }
    }

    // 卡片样式
    .card {
        background-color: @card-bg;
        border-radius: 16px;
        overflow: hidden;
        box-shadow: @shadow-base;
        transition: all 0.3s ease;
        cursor: pointer;

        &:hover {
            transform: translateY(-5px);
            box-shadow: @shadow-active;
        }

        &.card-active {
            transform: translateY(-5px);
            box-shadow: @shadow-active;
        }

        // 卡片图片容器
        .card-image-container {
            position: relative;

            // 卡片标签
            .card-tag {
                position: absolute;
                top: 16px;
                right: 16px;
                padding: 4px 12px;
                border-radius: 9999px;
                font-size: 14px;
                font-weight: 500;
            }
        }

        // 卡片内容
        .card-content {
            padding: 20px;

            .card-title {
                font-size: 18px;
                font-weight: bold;
                color: @text-primary;
                margin-bottom: 8px;
            }

            .card-description {
                color: @text-secondary;
                text-wrap: balance;
                margin-bottom: 12px;
                line-height: 1.5;
                font-size: 14px;
            }

            // 卡片底部
            .card-footer {
                display: flex;
                align-items: center;
                justify-content: space-between;
                margin-top: 12px;

                .card-meta {
                    color: @accent-color;
                    font-weight: 500;
                    font-size: 13px;

                    .fa {
                        margin-right: 1px;
                    }
                }

                // 爱心按钮区域
                .heart {
                    display: flex;
                    align-items: center;
                    gap: 4px;

                    .like-count {
                        font-size: 13px;
                        color: @text-secondary;
                    }

                    .action-btn {
                        position: relative;
                        cursor: pointer;
                    }

                    .heart-checkbox {
                        position: absolute;
                        opacity: 0;
                        cursor: pointer;
                        height: 0;
                        width: 0;
                    }

                    .heart-btn {
                        position: relative;
                        width: 10px;
                        height: 10px;
                        transition: transform 0.2s;
                        display: inline-flex;
                        align-items: center;
                        justify-content: center;

                        &:hover {
                            transform: scale(1.1);
                        }
                    }

                    .heart-icon {
                        position: absolute;
                        top: 0;
                        left: -5px;
                        width: 100%;
                        height: 100%;
                        transition: color 0.3s;
                        display: flex;
                        align-items: center;
                        justify-content: center;

                        &::before {
                            content: '❤';
                            font-size: 1.25rem;
                            color: @gray-light;
                            transition: color 0.3s, transform 0.3s;
                            position: relative;
                            line-height: 1;
                            vertical-align: middle;
                            transform-origin: center;
                        }
                    }

                    // 选中状态样式
                    .heart-checkbox:checked~.heart-btn .heart-icon::before {
                        color: @danger-color;
                        animation: heartBeat 0.5s cubic-bezier(0.17, 0.89, 0.32, 1.49);
                    }
                }
            }
        }
        .employee {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;

            .van-tag {
                font-size: 12px;
                padding: 4px 8px;
                border-radius: 9999px;
                background-color: #7B68EE;
                color: white;
            }
        }
    }
}
</style>