<template>
    <el-popover placement="bottom-end" :width="674" trigger="click" v-bind:popper-options="popperOptions"
        popper-style="padding:0;border-radius: 10px;">
        <template #reference>
            <div ref="btn" class="btn" @click="transmit"></div>
        </template>

        <div class="transmit-unfold-box">
            <!-- <div v-if="props['concatType']" class="arrow" style="right: 300px;"></div>
            <div v-else class="arrow" :style="{ right: type == 'apartment' ? '182px' : '75px' }"></div> -->
            <div class="transmit-item">
                <div class="transmit-head">转发网页版</div>
                <div class="transmit-box transmit-webpage-box">
                    <div class="transmit-webpage-title">{{ props['title'] }}</div>
                    <div class="transmit-link">{{ url }}</div>
                </div>
                <div class="copy-link-btn flexcenter" @click="copy">复制链接</div>
            </div>
            <div class="transmit-item">
                <div class="transmit-head">转发小程序版</div>
                <div class="transmit-box transmit-QRCode-box"><img :src="props['qrcode']" class="QRCode">
                    <div class="hint">
                        <img class="saoma-icom" src="@/assets/img/apartmentDetail/scan-icon.png">
                        手机查看该{{ type == 'apartment' ? '公寓' : '房源' }}
                    </div>
                </div>
            </div>
        </div>
    </el-popover>
</template>

<script setup>
import { defineProps, nextTick, ref, watch } from 'vue';
import { copyToClipboard } from '@/utils/util.js'
import { ElMessage } from 'element-plus'

const props = defineProps({
    title: String,
    qrcode: String,
    type: String, // housing  housingTop  apartment
    concatType: Boolean,
})

const popperOptions = ref({
    modifiers: [
        {
            name: 'offset',
            options: {
                offset: [38, 0] // 设置左偏移为20px，右偏移为0px
            }
        }
    ]
});

watch(() => props.concatType, (newValue, oldValue) => {

    nextTick(() => {
        if (newValue && props['type'] != 'apartment') popperOptions.value['modifiers'][0]['options']['offset'][0] = 235
        else if (props['type'] != 'apartment') popperOptions.value['modifiers'][0]['options']['offset'][0] = 38
        else popperOptions.value['modifiers'][0]['options']['offset'][0] = 14
    })

});


// popperOptions.value['modifiers'][0]['options']['offset'][0] = 235

// popperOptions.value['modifiers'][0]['options']['offset'][0] = 14

let url = location.href

let popover = ref(null)
let btn = ref(null)


setTimeout(() => {
    console.log(popover, "popover");
}, 3000)

const copy = () => {
    copyToClipboard(`${props['title']} - ${url}`).then(() => {
        ElMessage.success("复制成功！！！")
    })
}

</script>

<style lang="less" scoped>
.el-popper__arrow {
    left: 200px;
}

.btn {
    // background-color: antiquewhite;
    width: 100px;
    height: 40px;
    position: absolute;
    // top: 0;
    // left: 0;
}

.transmit-unfold-box,
.transmit-unfold-box * {
    box-sizing: content-box;
}

.transmit-unfold-box {
    background-color: #fff;
    padding: 42px 54px 12px 44px;
    display: flex;
    border-radius: 10px;
    font-family: "PingFang SC", "Helvetica Neue", Helvetica, "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
    // box-shadow: 0px 2px 11px -2px #dcebef;
    // border: 1px solid #e0e0e0;
}

.transmit-unfold-box .transmit-unfold-close {
    display: flex;
    justify-content: flex-end;
    position: absolute;
    top: 0;
    right: 0;
}

.transmit-unfold-box .transmit-unfold-close .transmit-close-icon {
    width: 16px;
    height: 16px;
    padding: 10px 12px;
    cursor: pointer;
}

.transmit-unfold-box .transmit-item {
    display: flex;
    flex-direction: column;
}

.transmit-unfold-box .transmit-item:last-of-type {
    margin-left: 74px;
}

.transmit-unfold-box .transmit-item .transmit-head {
    font-size: 16px;
    line-height: 16px;
    font-weight: 550;
    color: #000;
}

.transmit-unfold-box .transmit-item .transmit-box {
    border-radius: 16px;
    border: 1px solid #f0f0f0;
    margin-top: 28px;
    margin-bottom: 32px;
}

.transmit-unfold-box .transmit-item .transmit-webpage-box {
    width: 265px;
    padding: 12px 18px 12px 15px;
    font-size: 14px;
}

.transmit-unfold-box .transmit-item .transmit-webpage-box .transmit-webpage-title {
    line-height: 24px;
    word-break: break-word;
    color: #000;
}

.transmit-unfold-box .transmit-item .transmit-webpage-box .transmit-link {
    line-height: 18px;
    color: #a0a0a0;
    word-wrap: break-word;
}

.transmit-unfold-box .transmit-item .transmit-QRCode-box {
    width: 198px;
    // height: 128px;
    flex-direction: column;
    padding: 20px 0;
    display: flex;
    justify-content: space-between;
}

.transmit-unfold-box .transmit-item .transmit-QRCode-box .QRCode {
    // width: 98px;
    // height: 98px;
    height: 130px;
    margin: 0 auto;
}

.transmit-unfold-box .transmit-item .transmit-QRCode-box .hint {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    text-align: center;
    margin-top: 20px;
}

.transmit-unfold-box .transmit-item .transmit-QRCode-box .hint .saoma-icom {
    width: 14px;
    height: 14px;
    margin-right: 8px;
}

.transmit-unfold-box .copy-link-btn {
    background-color: #46dfba;
    border-radius: 5px;
    width: 120px;
    height: 38px;
    user-select: none;
    cursor: pointer;
    color: #000;
}

.arrow {
    width: 10px;
    height: 10px;
    z-index: -1;
    position: absolute;
    top: -4px;
    right: 75px;

    &::before {
        content: "";
        border: 1px solid #e4e7ed;
        border-bottom-color: transparent !important;
        border-right-color: transparent !important;
        position: absolute;
        width: 10px;
        height: 10px;
        background-color: #fff;
        // z-index: -1;
        transform: rotate(45deg);
        // background: red;
        box-sizing: border-box;
    }
}
</style>