<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>记忆</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="/css/index.css">
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;600&display=swap" rel="stylesheet">
    <script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/2.1.3/jquery.min.js">
    </script>
</head>
<body>
<div class="container">
    <h1 class="main-title">我们的相册</h1>

    <!-- 相册选择模块 -->
    <div class="album-selection" id="albumSelection">
        <!-- 相册卡片将通过JS动态生成 -->
        @foreach($photo_album as $album)
            <div class="album-card" onclick="window.location.href = '/detail?id={{ $album->id }}';">
                <div class="album-cover" style="background-image: url({{ $album->url }})">
                    <div class="album-overlay">
                        <div class="album-info">
                            <h3 class="album-title">{{ $album->title }}</h3>
                            <p class="album-date">{{ $album->created_at }}</p>
                        </div>
                    </div>
                </div>
            </div>
        @endforeach
    </div>
</div>

<!-- 图片预览模态框 -->
<div class="preview-modal" id="previewModal">
    <button class="close-modal" id="closeModal">
        <i class="fas fa-times"></i>
    </button>

    <button class="nav-btn prev-btn" id="prevBtn">
        <i class="fas fa-chevron-left"></i>
    </button>

    <div class="modal-content">
        <img class="modal-img" id="modalImg" src="" alt="预览图片">

        <div class="modal-tools">
            <button class="tool-btn" id="rotateLeft" title="向左旋转">
                <i class="fas fa-undo"></i>
            </button>
            <button class="tool-btn" id="rotateRight" title="向右旋转">
                <i class="fas fa-redo"></i>
            </button>
            <button class="tool-btn" id="downloadBtn" title="下载图片">
                <i class="fas fa-download"></i>
            </button>
        </div>
    </div>

    <button class="nav-btn next-btn" id="nextBtn">
        <i class="fas fa-chevron-right"></i>
    </button>
</div>

<script>
    const albums = <?php echo json_encode($photo_album) ?>;

    // DOM元素
    const albumSelection = document.getElementById('albumSelection');
    const albumDetail = document.getElementById('albumDetail');
    const detailTitle = document.getElementById('detailTitle');
    const photoGrid = document.getElementById('photoGrid');
    const previewModal = document.getElementById('previewModal');
    const modalImg = document.getElementById('modalImg');
    const closeModal = document.getElementById('closeModal');
    const rotateLeft = document.getElementById('rotateLeft');
    const rotateRight = document.getElementById('rotateRight');
    const downloadBtn = document.getElementById('downloadBtn');
    const prevBtn = document.getElementById('prevBtn');
    const nextBtn = document.getElementById('nextBtn');

    // 当前状态
    let currentAlbum = null;
    let currentPhotoIndex = 0;
    let currentPhotos = [];
    let currentRotation = 0;

    // 初始化雪花效果
    function createSnowflakes() {
        const width = window.innerWidth;
        const height = window.innerHeight;
        const count = Math.min(50, Math.floor(width * height / 20000));

        for (let i = 0; i < count; i++) {
            createSnowflake();
        }
    }

    function createSnowflake() {
        const snowflake = document.createElement('div');
        snowflake.className = 'snowflake';

        const shapes = ['❄', '❅', '❆', '✻', '✼', '✾', '✵'];
        snowflake.textContent = shapes[Math.floor(Math.random() * shapes.length)];

        const size = Math.random() * 0.8 + 0.2;
        snowflake.style.fontSize = `${size}em`;
        snowflake.style.opacity = Math.random() * 0.6 + 0.3;
        snowflake.style.left = `${Math.random() * window.innerWidth}px`;
        snowflake.style.top = '-20px';

        const duration = Math.random() * 5 + 5;
        snowflake.style.animationDuration = `${duration}s`;
        snowflake.style.animationDelay = `${Math.random() * 5}s`;

        document.body.appendChild(snowflake);

        snowflake.addEventListener('animationiteration', () => {
            snowflake.style.left = `${Math.random() * window.innerWidth}px`;
            snowflake.style.top = '-20px';
        });
    }

    // 窗口大小改变时重新创建雪花
    window.addEventListener('resize', () => {
        const snowflakes = document.querySelectorAll('.snowflake');
        snowflakes.forEach(snowflake => snowflake.remove());
        createSnowflakes();
    });

    // 初始化应用
    window.addEventListener('load', () => {
        createSnowflakes();
    });
</script>
</body>
</html>
