<template>
    <div v-if="show" class="image-save-guide-overlay">
        <div class="guide-content" @click.stop>
            <!-- 关闭按钮 -->
            <button class="close-button" @click="close">
                <span class="close-icon">×</span>
            </button>

            <!-- 图片区域 -->
            <div v-if="imageUrl" class="image-container">
                <img :src="imageUrl" class="guide-image" />
            </div>

            <!-- 文字内容区域 -->
            <div class="text-container">
                <div class="guide-title">{{ title }}</div>
                <div class="guide-instruction">长按图片保存</div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, watch } from 'vue';

const props = defineProps({
    show: {
        type: Boolean,
        default: false
    },
    imageUrl: {
        type: String,
        default: ''
    },
    title: {
        type: String,
        default: '保存图片到相册'
    }
});

const emit = defineEmits(['close']);

const close = () => {
    emit('close');
};

// 自动关闭功能已禁用
// watch(() => props.show, (newVal) => {
//     if (newVal && props.autoCloseDelay > 0) {
//         setTimeout(() => {
//             close();
//         }, props.autoCloseDelay);
//     }
// });
</script>

<style scoped>
.image-save-guide-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    box-sizing: border-box;
}

.guide-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 24px 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    color: #333;
    text-align: center;
    position: relative;
}

/* 关闭按钮 */
.close-button {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease;
    z-index: 10;
}

.close-button:hover {
    background: rgba(0, 0, 0, 0.2);
}

.close-icon {
    font-size: 20px;
    color: #666;
    font-weight: bold;
    line-height: 1;
}

/* 图片容器 */
.image-container {
    width: 100%;
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
}

.guide-image {
    max-width: 100%;
    max-height: 60vh;
    width: auto;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    object-fit: contain;
}

/* 文字容器 */
.text-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.guide-title {
    font-size: 20px;
    font-weight: 600;
    color: #1a1a1a;
    line-height: 1.3;
    margin-bottom: 4px;
}

.guide-instruction {
    font-size: 16px;
    color: #4a4a4a;
    line-height: 1.4;
    font-weight: 500;
}

/* 超小屏幕 (320px - 375px) */
@media (max-width: 375px) {
    .image-save-guide-overlay {
        padding: 12px;
    }

    .guide-content {
        padding: 20px 16px;
        max-width: 100%;
    }

    .guide-title {
        font-size: 18px;
    }

    .guide-instruction {
        font-size: 15px;
    }

    .close-button {
        width: 28px;
        height: 28px;
        top: 10px;
        right: 10px;
    }

    .close-icon {
        font-size: 18px;
    }

    .guide-image {
        max-height: 50vh;
    }
}

/* 小屏幕 (376px - 414px) */
@media (min-width: 376px) and (max-width: 414px) {
    .guide-content {
        padding: 22px 18px;
    }

    .guide-title {
        font-size: 19px;
    }
}

/* 中等屏幕 (415px - 480px) */
@media (min-width: 415px) and (max-width: 480px) {
    .guide-content {
        padding: 24px 20px;
    }

    .guide-title {
        font-size: 20px;
    }
}

/* 大屏幕 (481px+) */
@media (min-width: 481px) {
    .guide-content {
        padding: 28px 24px;
        max-width: 420px;
    }

    .guide-title {
        font-size: 22px;
    }

    .guide-instruction {
        font-size: 17px;
    }
}

/* 横屏适配 */
@media (orientation: landscape) and (max-height: 500px) {
    .guide-content {
        padding: 16px 20px;
    }

    .image-container {
        margin-bottom: 12px;
    }

    .guide-image {
        max-height: 40vh;
    }

    .text-container {
        gap: 8px;
    }

    .guide-title {
        font-size: 18px;
        margin-bottom: 2px;
    }

    .guide-instruction {
        font-size: 15px;
    }
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
    .guide-content {
        background: rgba(30, 30, 30, 0.95);
        color: #e5e5e5;
    }

    .guide-title {
        color: #ffffff;
    }

    .guide-instruction {
        color: #d1d5db;
    }
}
</style>