<!-- 自定义卡片红包封面 -->
<template>
    <div class="not-open">
        <img class="cover" :src="require('@/assets/subject/001-card.png')"  />
        <img class="open-gif" :src="require('@/assets/gif/001.gif')" />

        <img
            :src="require('@/assets/svg/icon-open.svg')"
            class="open"
            @click="open"
        />
        <div class="title" v-if="data.userInfo">
            <img :src="data.userInfo.avatarUrl" />
            <span>{{
                data.userInfo.nickName || "FutureDoctor"
            }}</span>
        </div>
        <div class="money-area">
            <div class="txt">{{data.currencyCode == 'USD' ? 'USD' : data.tokenSymbol}} GIVEAWAY</div>
            <div class="coin">
                <img :src="data.currencyIconUrl" />
                <span id="preview-after-amount"
                    :style="{
                        fontSize: amountFontSize + 'px'
                    }">{{ data.amountValue }}</span>
            </div>
            <div class="people">
                {{ data.totalCount }} WINNERS TO SHARE
            </div>
        </div>
    </div>
</template>

<script setup>
import { defineProps, defineEmits, watch, ref } from "vue";

const props = defineProps({
    data: {
        type: Object,
        default: () => {
            return {
                totalCount: 0,
                amountValue: 0,
                tokenSymbol: "",
                userInfo: {
                    avatarUrl: "",
                    nickName: "",
                },
            };
        },
    },
});

let amountFontSize = ref(60);

watch(() => props.data, () => {
    let lenstr = document.querySelector('#preview-after-amount').innerHTML.length;
    let num = parseInt(360/lenstr);
    amountFontSize.value = num < 56 ? num : 56;
})


const emits = defineEmits(["clickOpenRedPacket"]);

const open = () => {
    emits("clickOpenRedPacket", {});
};
</script>

<style scoped lang="scss">
.not-open {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0px 2px 20px rgba(0, 0, 0, 0.1));
    position: relative;
    border-radius: 16px;

    .money-area {
        width: 100%;
        position: absolute;
        top: 65px;

        .txt {
            font-weight: 800;
            font-size: 16px;
            text-align: center;
            letter-spacing: 0.3px;
            color: #ffffff;
        }

        .coin {
            text-align: center;
            width: 100%;
            padding: 6px 0;
            margin: 0 auto;
            display: flex;
            align-items: center;
            justify-content: center;

            img {
                width: 46px;
                height: 46px;
                border-radius: 50%;
                border: 3px solid #ffffff;
            }

            span {
                margin-left: 15px;
                font-weight: 800;
                font-size: 60px;
                line-height: 76px;
                color: #ffffff;
            }
        }

        .people {
            font-weight: 800;
            font-size: 13px;
            line-height: 16px;
            letter-spacing: 0.05em;
            text-align: center;
            color: #ffffff;
        }
    }

    .title {
        position: absolute;
        top: 15px;
        left: 15px;
        z-index: 3;
        width: 100%;
        display: flex;
        align-items: center;

        img {
            width: 24px;
            height: 24px;
            border: 2px solid #fff;
            border-radius: 50%;
        }

        span {
            margin-left: 10px;
            font-weight: 600;
            font-size: 16px;
            letter-spacing: 0.3px;
            color: #fff;
        }
    }

    // .txt {
    //   width: 100%;
    //   position: absolute;
    //   font-style: normal;
    //   font-weight: 700;
    //   font-size: 42px;
    //   line-height: 50px;
    //   text-align: center;

    //   color: #FFF2D3;
    //   top: 90px;
    //   z-index: 3;
    // }

    img {
        width: 100%;
    }

    .cover {
        border-radius: 16px;
    }

    .up {
        position: absolute;
        top: 0;
        // box-shadow: 0px 4px 44px rgba(0, 0, 0, 0.1);
        z-index: 1;
    }

    .down {
        position: absolute;
        top: 253px;
    }

    .open {
        width: 335px;
        height: 50px;
        cursor: pointer;
        position: absolute;
        bottom: 28px;
        left: 50%;
        margin-left: -167.5px;
        z-index: 2;
    }

    .open-gif {
        width: 200px;
        height: 200px;
        text-align: center;
        position: absolute;
        bottom: 90px;
        left: 50%;
        margin-left: -100px;
        z-index: 3;
    }
}
</style>
