<script setup lang="ts">
import { cssAssetUrl } from '@/commons/assets.ts';
import { $read } from '@/commons/utils';
import { useAdminGameSocket } from '@/composables/useAdminGameSocket';
import router from '@/router';
import { onMounted, onUnmounted, ref } from 'vue';

const imageUrls = {
    bg1: cssAssetUrl('main-bg1.png'),
    logo: cssAssetUrl('game1/logo.png'),
    title1: cssAssetUrl('main-title.webp'),

    icon1: cssAssetUrl('icon1.png'),
    icon2: cssAssetUrl('icon2.png'),
    icon3: cssAssetUrl('icon3.png'),
    icon4: cssAssetUrl('icon4.png'),
    icon5: cssAssetUrl('icon5.png'),
    icon6: cssAssetUrl('icon6.png'),
}
const iconUrls = [
    imageUrls.icon1,
    imageUrls.icon2,
    imageUrls.icon3,
    imageUrls.icon4,
    imageUrls.icon5,
    imageUrls.icon6,
]

const list = ref(['击鼓齐福', '聚宝接福',
    '马上有福', '策马迎福', '圈彩纳福', '福运当头'
])
const show_login = ref(false);
const item_index = ref(0);
const gameHandler = async (index: number) => {
    item_index.value = index;
    let token = $read('token', '')
    if (!token) {
        //需要登录
        show_login.value = true;
        return;
    }
    await router.replace(`/game${index + 1}`);
}

useAdminGameSocket({})
</script>

<template>
    <div class="bg">
        <div class="img-logo"></div>
        <div class="img-title1"></div>
        <div class="rule-container">
            <div>
                <div class="rule-title">游戏规则</div>
                <div class="rule-text">
                    扫码即玩，大屏实时同步。每局结束大屏公布前10名。主持人邀请获奖用户，凭获奖界面作为凭证，上台领奖。，核对后发放实物奖品。奖品不折现、不替换，逾期作废。
                </div>
            </div>
        </div>
        <div class="game-container">
            <div v-for="item, index in list" @click="gameHandler(index)">
                <div class="card">
                    <div class="img">
                        <div :style="{ background: `${iconUrls[index]} center / cover no-repeat` }"></div>
                    </div>
                    <div class="btn">{{ item }}</div>
                </div>
            </div>
        </div>
    </div>
</template>

<style scoped>
.bg {
    width: 1920px;
    height: 1080px;
    background: v-bind('imageUrls.bg1') center / cover no-repeat;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;

    .img-logo {
        background: v-bind('imageUrls.logo');
        background-size: cover;
        width: 428px;
        height: 77px;
        position: absolute;
        left: 37px;
        top: 82px;
    }

    .img-title1 {
        background: v-bind('imageUrls.title1') center / cover no-repeat;
        width: 1024px;
        height: 143px;
        margin: 0 auto;
        position: relative;
        top: 50px;
    }

    .rule-container {
        box-sizing: border-box;
        width: 638px;
        min-height: 162px;
        border-radius: 12px;
        color: white;
        position: absolute;
        left: 50%;
        top: 341px;
        transform: translateX(-50%);
        font-weight: 700;

        text-shadow:
            -1px -1px 0 #000,
            1px -1px 0 #000,
            -1px 1px 0 #000,
            1px 1px 0 #000;
        background: rgba(0, 0, 0, 0.25);
        backdrop-filter: blur(5px);
        border: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);

        >div {
            padding: 27px 34px 24px;
            background: rgba(0, 0, 0, 0.15);
            border-radius: 12px;
        }

        .rule-title {
            margin-bottom: 12px;
            font-size: 22px;
            line-height: 1.2;
            text-align: center;
        }

        .rule-text {
            font-size: 16px;
            line-height: 1.58;
        }

    }

    .game-container {
        display: flex;
        justify-content: space-between;
        flex-direction: row;
        width: 1220px;
        height: 250px;
        position: absolute;
        left: 50%;
        bottom: 250px;
        transform: translateX(-50%);

        .card {
            padding: 10px;
            cursor: pointer;

            .img {
                width: 150px;
                height: 150px;
                background: white;
                border-radius: 20px;
                position: relative;
                transition: transform 0.2s ease 0.1s;

                >div {
                    width: 100%;
                    height: 100%;
                    border-radius: 20px;
                    position: absolute;
                }
            }

            .btn {
                width: 150px;
                height: 56px;
                line-height: 56px;
                background: #FFDF9E;
                text-align: center;
                color: #7D1F00;
                font-weight: bold;
                border-radius: 15px;
                margin-top: 20px;
            }

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

}
</style>
