<template>
    <div class="floor-area flexacenter" :class="{ 'show': isLoaded }">
        <div class="floor-content flexacenter">
            <!-- {{ isLoaded }} -->
            <div class="floor-left flexacenter">
                <div class="item flexacenter" style="cursor: auto;">
                    <img class="icon" src="@/assets/img/eye-icon.svg" />
                    {{ info["views"] }}
                </div>
                <div class="item flexacenter" @click="handleLike">
                    <img class="icon" v-if="islike == 1" src="@/assets/img/like-icon-colours.png" />
                    <img class="icon" v-else src="@/assets/img/like-icon.png" />
                    {{ info["likes"] || "" }}
                </div>
                <div class="item flexacenter" @click="handleCollect()">
                    <img class="icon" v-if="iscollection == 1" src="@/assets/img/collect-icon-colours.svg" />
                    <img class="icon" v-else src="@/assets/img/collect-icon.png" />
                    {{ info["favs"] || "收藏" }}
                </div>
                <ClientOnly>
                    <el-popover placement="bottom" width="628px" trigger="click" popper-style="padding: 0;border-radius: 10px;" v-model:visible="transmitBoxState">
                        <template #reference>
                            <div class="item flexacenter" @click="handleShare"><img class="icon" src="@/assets/img/transmit-icon.png" />转发</div>
                        </template>

                        <div class="transmit-box flexflex">
                            <img class="cross-icon" @click.stop="transmitBoxState = false" src="@/assets/img/cross-icon.png" />
                            <div class="transmit-left transmit-web">
                                <div class="transmit-title">转发网页版</div>
                                <div class="transmit-content">
                                    <div class="transmit-headline">{{ info["title"] }}</div>
                                    <div class="transmit-url">{{ getFullUrl() }}</div>
                                </div>
                                <div class="transmit-web-btn flexcenter" @click="copyText(`${info['title']} + ${getFullUrl()}`)">复制链接</div>
                            </div>
                            <div class="transmit-right transmit-mini">
                                <div class="transmit-title">转发小程序版</div>
                                <div class="transmit-content flexcenter">
                                    <img class="transmit-mini-img" :src="qrcode" />
                                    <div class="flexcenter">
                                        <img class="give-sweep" src="@/assets/img/give-sweep.png" />
                                        扫码转发该问答
                                    </div>
                                </div>
                            </div>
                        </div>
                    </el-popover>
                </ClientOnly>
            </div>
            <div class="floor-middle flexacenter coin-box" v-if="false">
                <div class="coin-content flexacenter flex1" @click="openCoinRankList">
                    <img class="coin-icon" src="@/assets/img/coin-icon.png" />
                    <div class="coin-text flex1 flexacenter">
                        已获
                        <div class="coin-value">{{ info.coins }}</div>
                        个寄托币
                    </div>
                </div>
                <div class="coin-btn flexcenter" @click="openCoinOperation()">给TA投币</div>
            </div>

            <div class="floor-right flexacenter" @mouseenter="handleFloorRight(true)" @mouseleave="handleFloorRight(false)">
                手机查看该投票
                <img class="arrows-icon" src="@/assets/img/arrows-icon.png" />
                <el-popover placement="bottom" width="160px" trigger="hover" v-model:visible="floorRightState" popper-style="padding: 24px;border-radius: 18px;">
                    <template #reference>
                        <div class="QR-code-ball flexcenter">
                            <img class="" src="@/assets/img/QR-code-icon.svg" />
                        </div>
                    </template>
                    <img class="examine-code" :src="qrcode" />
                </el-popover>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ElMessage } from "element-plus"

let isNeedLogin = inject("isNeedLogin")
const goLogin = inject("goLogin")

let info = inject("info")
let islike = inject("islike")
let iscollection = inject("iscollection")
let qrcode = inject("qrcode")
let token = inject("token")
const topHeadRef = inject("topHeadRef")
const isLoaded = inject("isLoaded")

// 获取完整 url
const getFullUrl = () => {
    if (typeof window === "undefined") return
    return window.location.href
}

// 复制
let copyText = text => {
    if (navigator.clipboard) {
        copyText = () => {
            navigator.clipboard.writeText(text)
            ElMessage.success("复制成功")
        }
    } else {
        copyText = () => {
            var tempInput = document.createElement("input")
            tempInput.value = text
            document.body.appendChild(tempInput)
            tempInput.select()
            document.execCommand("copy")
            document.body.removeChild(tempInput)
            ElMessage.success("复制成功")
        }
    }
    copyText()
}

let floorRightState = ref(false) // 右下角 的二维码显示状态

// 处理右下角 鼠标经过箭头 展示二维码
const handleFloorRight = value => {
    floorRightState.value = value
}

// 点击 收藏
const handleCollect = () => {
    if (isNeedLogin.value) {
        goLogin()
        return
    }

    topHeadRef.value.count = {}

    operateCollectHttp({ token: token.value }).then(res => {
        if (res.code != 200) {
            ElMessage.error(res["message"])
            return
        }
        let data = res.data

        info.value["favs"] = data["count"]
        iscollection.value = data["status"]

        ElMessage.success(res["message"])
    })
}

const isBrowser = computed(() => {
    return process.client // 使用 process.client 判断是否在浏览器环境下
})

// 点赞
const handleLike = () => {
    if (isNeedLogin.value) {
        goLogin()
        return
    }

    if (islike.value) {
        ElMessage.error("不可取消点赞")
        return
    }

    operateLikeHttp({ token: token.value }).then(res => {
        if (res.code != 200) {
            ElMessage.error(res.message)
            return
        }

        let data = res.data
        info.value["likes"] = data["count"]
        islike.value = data["status"]

        ElMessage.success(res.message)
    })
}

// 底部转发弹窗显示 状态
let transmitBoxState = ref(false)
</script>

<style scoped lang="less">
.floor-area {
    position: fixed;
    left: 0;
    bottom: 0;
    // bottom: 50%;
    width: 100vw;
    min-width: 1200px;
    height: 70px;
    z-index: 1;
    background-color: rgba(255, 255, 255, 1);
    -moz-box-shadow: 0px -1px 2px rgba(0, 0, 0, 0.192156862745098);
    -webkit-box-shadow: 0px -1px 2px rgba(0, 0, 0, 0.192156862745098);
    box-shadow: 0px -1px 2px rgba(0, 0, 0, 0.192156862745098);
    display: none;
    &.show {
        display: flex;
        animation: animafloor 1s forwards;
        animation-timing-function: cubic-bezier(0.98, -0.2, 0.55, 0.97); /* 先快后慢的时间曲线 */
        animation-fill-mode: both;
    }
    .floor-content {
        width: 1200px;
        height: 100%;
        margin: 0 auto;
        padding: 0 30px;
        display: flex;
        justify-content: space-between;
        .floor-left {
            .item {
                cursor: pointer;
                color: #aaaaaa;
                font-size: 13px;
                margin-right: 50px;
                .icon {
                    width: 16px;
                    margin-right: 5px;
                    // animation: anima 1s forwards;
                }

                // :nth-of-type(1) {
                //     animation-delay: 1s;
                // }
                // :nth-of-type(2) {
                //     animation-delay: 2s;
                // }

                &.operate-item {
                    position: relative;
                    display: flex;
                    justify-content: center;
                }
            }
        }

        .floor-middle {
            min-width: 300px;
            height: 40px;
            background-color: rgba(246, 246, 246, 1);
            border-radius: 150px;
            .coin-content {
                padding: 0 13px;
                height: 100%;
                cursor: pointer;

                .coin-icon {
                    width: 20px;
                    height: 24px;
                    margin-right: 5px;
                    margin-top: -2px;
                }

                .coin-text {
                    font-size: 13px;
                    color: #333333;
                    .coin-value {
                        font-family: "Arial-Black", "Arial Black", sans-serif;
                        font-weight: 900;
                        margin: 0 5px;
                    }
                }
            }

            .coin-btn {
                width: 97px;
                height: 40px;
                background-color: rgba(114, 219, 134, 1);
                border-radius: 150px;
                color: #ffffff;
                font-size: 13px;
                cursor: pointer;
            }
        }

        .floor-right {
            color: #7f7f7f;
            font-size: 13px;
            cursor: pointer;

            .arrows-icon {
                width: 12px;
                height: 12px;
                margin: 0 10px;
            }

            .QR-code-ball {
                width: 40px;
                height: 40px;
                background-color: rgba(246, 246, 246, 1);
                border-radius: 20px;
                cursor: pointer;
            }
        }
    }
}

.transmit-box {
    width: 628px;
    border-radius: 10px;
    justify-content: space-between;
    padding: 40px 35px 42px;
    // z-index: 3;
    cursor: auto;

    .cross-icon {
        width: 22px;
        height: 22px;
        position: absolute;
        top: 6px;
        right: 6px;
        cursor: pointer;
        padding: 6px;
    }

    .transmit-title {
        font-weight: 650;
        font-size: 16px;
        color: #000000;
        line-height: 24px;
        margin-bottom: 24px;
    }

    .transmit-content {
        border: 1px solid rgba(242, 242, 242, 1);
        border-radius: 16px;
    }

    .transmit-web {
        .transmit-content {
            width: 300px;
            font-size: 14px;
            line-height: 24px;
            padding: 14px 16px;
            margin-bottom: 32px;

            .transmit-headline {
                color: #333333;
            }

            .transmit-url {
                color: #aaaaaa;
                word-wrap: break-word;
            }
        }

        .transmit-web-btn {
            width: 120px;
            height: 38px;
            background-color: rgba(114, 219, 134, 1);
            border-radius: 8px;
            font-size: 14px;
            color: #fff;
            cursor: pointer;
        }
    }

    .transmit-mini {
        .transmit-content {
            flex-direction: column;
            padding: 22px 44px;

            .transmit-mini-img {
                width: 90px;
                height: 90px;
                margin-bottom: 21px;
            }

            color: #555555;
            // line-height: 22px;
            font-size: 13px;

            .give-sweep {
                width: 12px;
                height: 12px;
                margin-right: 8px;
            }
        }
    }
}

.examine-code {
    width: 113px;
    height: 113px;
}

@keyframes anima {
    0% {
        width: 16px;
    }

    40% {
        width: 20px;
    }

    100% {
        width: 16px;
    }
}

@keyframes animafloor {
    0% {
        // left: -100%;
        // opacity: 0;
        transform: translate3d(-100%, 0, 0);
    }

    90% {
        left: 20px;
    }

    100% {
        // left: 0;
        // opacity: 1;
        transform: translateZ(0);
    }
}
</style>
