<!-- 自定义封装弹层 -->
<template>
    <el-dialog
        v-model="dialogVisible"
        :close-on-press-escape="false"
        :show-close="false"
        :top="top"
        append-to-body
        class="super-dialog"
        close-on-click-modal
        v-bind="attrs"
    >
        <!-- 关闭图标 -->
        <el-icon class="close-icon" @click="dialogVisible = false">
            <Close />
        </el-icon>
        <!-- 自定义头部内容 -->
        <div class="super-dialog-title">
            <div class="title-left">
                <span class="title">
                    {{ title }}
                </span>
                <el-tooltip
                    v-if="hintLanguage"
                    :content="hintLanguage"
                    class="prompt"
                    effect="dark"
                    placement="bottom-start"
                    popper-class="prompt-popper"
                >
                    <img :src="questionIcon" alt="" class="question-icon" />
                </el-tooltip>
            </div>
            <div class="title-end">
                <slot name="title-end"></slot>
            </div>
        </div>
        <!-- 内容默认插槽 -->
        <div class="super-dialog-content">
            <slot></slot>
        </div>
        <!-- 尾部按钮插槽 -->
        <template #footer>
            <slot name="footer"></slot>
        </template>
    </el-dialog>
</template>

<script setup>
import { computed, useAttrs } from 'vue'
import questionIcon from '@/assets/img/common/question-circle.png'

const attrs = useAttrs()

const props = defineProps({
    modelValue: {
        default: false,
        type: Boolean
    },
    title: {
        default: '标题',
        type: String
    },
    // 距离页面顶部高度
    top: {
        default: '20vh',
        type: String
    },
    // 提示语
    hintLanguage: {
        default: '',
        type: String
    }
})

const emit = defineEmits(['update:modelValue'])

const dialogVisible = computed({
    get() {
        return props.modelValue
    },
    set(val) {
        emit('update:modelValue', val)
    }
})
</script>

<style lang="scss">
.el-dialog.super-dialog {
    box-sizing: border-box;
    background-color: var(--theme-system-bg);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 0 15px rgba(#0d0d0d, 0.4);
    padding: 0;

    .super-dialog-title {
        width: 100%;
        height: 44px;
        display: flex;
        justify-content: space-between;
        background:
            url('@/assets/img/layout/header-bg.png') no-repeat 50% 50%,
            linear-gradient(
                180deg,
                var(--theme-system-module-1) 0%,
                var(--theme-system-module-1) 100%
            );
        background-size: 100% 100%;
        color: var(--theme-text-inverse);
        padding: 0 20px;
        box-sizing: border-box;
        user-select: none;

        > * {
            height: 100%;
        }

        .title-left {
            display: flex;
            align-items: center;

            .title {
                width: 100%;
                font-size: 17px;
                font-weight: bold;
            }

            .question-icon {
                width: 20px;
                height: 20px;
                margin-left: 10px;
            }

            .prompt {
                width: 19px;
                height: 19.5px;
                margin: 0 8px;
                cursor: pointer;
            }
        }

        .title-end {
            display: flex;
            align-items: center;
        }
    }

    .super-dialog-content {
        box-sizing: border-box;
        padding: 20px;
    }

    .el-dialog__header {
        width: 0;
        height: 0;
        padding: 0;
    }

    .el-dialog__body {
        padding: 0;
    }

    .el-dialog__footer {
        padding-top: 0;
    }

    .close-icon {
        position: absolute;
        top: 14px;
        right: 16px;
        color: var(--theme-text-inverse);
        cursor: pointer;
        transition: color 0.15s;
        font-size: 18px !important;
        font-weight: bold !important;

        &::before {
            font-size: 18px !important;
        }

        &:hover {
            color: $system-hover-active-text;
        }
    }
}

.prompt-popper {
    font-size: 13.5px !important;
}
</style>

<style lang="scss"></style>
