<!-- 自定义封装弹层 -->
<template>
    <el-drawer
        class="common-drawer"
        v-bind="attrs"
        v-model="dialogVisible"
        :show-close="false"
        close-on-click-modal
        :with-header="false"
        append-to-body
        :close-on-press-escape="false"
    >
        <!-- 关闭图标 -->
        <el-icon class="close-icon" v-if="showClose" @click="dialogVisible = false"
            ><Close
        /></el-icon>
        <!-- 自定义头部内容 -->
        <div class="common-drawer-title">
            <div class="title-left">
                <span class="title">
                    {{ title }}
                </span>
                <el-tooltip
                    v-if="hintLanguage"
                    class="prompt"
                    effect="dark"
                    :content="hintLanguage"
                    placement="bottom-start"
                    popper-class="prompt-popper"
                >
                    <img class="question-icon" :src="questionIcon" alt="" />
                </el-tooltip>
            </div>
            <div class="title-end">
                <slot name="title-end"></slot>
            </div>
        </div>
        <!-- 内容默认插槽 -->
        <div :class="['common-drawer-content', attrs.noPadding ? 'no-padding' : '']">
            <slot></slot>
        </div>
        <!-- 尾部按钮插槽 -->
        <template #footer v-if="$slots.footer">
            <slot name="footer"></slot>
        </template>
    </el-drawer>
</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
    },
    // 提示语
    hintLanguage: {
        default: '',
        type: String
    },
    showClose: {
        default: true,
        type: Boolean
    }
})

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

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

<style lang="scss">
.common-drawer {
    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;

    .common-drawer-title {
        width: 100%;
        height: 56px;
        display: flex;
        justify-content: space-between;
        // background:
        //     url('@/assets/img/layout/header-bg.png') no-repeat 50% 50%,
        //     linear-gradient(180deg, var(--theme-header-bg) 0%, var(--theme-header-bg) 100%);
        // background-size: 100% 100%;
        background: var(--theme-header-container-bg);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        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;
        }
    }
    .el-drawer__body {
        display: flex;
        flex-direction: column;
        padding: 0;
        overflow: hidden;
    }
    .common-drawer-content {
        box-sizing: border-box;
        padding: 20px;
        flex: 1;
        overflow: auto;
    }
    .common-drawer-content.no-padding {
        padding: 0;
    }
    .el-drawer__footer {
        padding-top: 20px;
    }

    .close-icon {
        position: absolute;
        top: 20px;
        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: 13px !important;
}
</style>

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