<template>
	<div class="fix-hot-image is-bg" :style="baseStyle">
		<div class="inner">
			<template v-if="data.pic">
				<img :src="data.pic" class="img" />
			</template>
			<template v-else>
				<div class="empty">
					<span>图片热区</span>
				</div>
			</template>
		</div>
	</div>
</template>

<script lang="ts" name="fix-hot-image" setup>
import { ref, computed, type PropType } from "vue";
import { Form } from "../../types/form";

const props = defineProps({
	data: {
		type: Object as PropType<Form.HotImage>,
		default: () => {
			return {
				pic: ""
			};
		}
	},
	styleSpacing: {
		type: Object as PropType<Form.Spacing>,
		default: () => {
			return {
				marginTop: 0,
				marginBottom: 0,
				marginLR: 0,
				padding: 0,
				borderTopLR: 0,
				borderBottomLR: 0
			};
		}
	},
	styleColor: {
		type: Object as PropType<Form.Color>,
		default: () => {
			return {
				color: "#000",
				backgroundColor: "#FFFFFF",
				opacity: 1
			};
		}
	}
});
const baseStyle = computed(() => {
	return {
		margin: `${props.styleSpacing.marginTop / 2}px ${props.styleSpacing.marginLR / 2}px ${props.styleSpacing.marginBottom / 2}px ${props.styleSpacing.marginLR / 2}px`,
		color: props.styleColor.color,
		padding: `${props.styleSpacing.padding / 2}px`,
		"--opacity": props.styleColor.opacity,
		"--background": props.styleColor.backgroundColor,
		borderRadius: `${props.styleSpacing.borderTopLR / 2}px ${props.styleSpacing.borderTopLR / 2}px ${props.styleSpacing.borderBottomLR / 2}px  ${props.styleSpacing.borderBottomLR / 2}px`
	};
});
</script>

<style lang="scss" scoped>
.fix-hot-image {
	box-sizing: border-box;
	overflow: hidden;

	.inner {
		height: 100%;
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: center;
		.img {
			width: 100%;
			max-width: 100%;
			height: auto;
		}
		.empty {
			height: 120px;
			display: flex;
			justify-content: center;
			align-items: center;
			span {
				font-size: 26px;
				color: var(--el-text-color-placeholder);
			}
		}
	}
}
.is-bg {
	position: relative;
	z-index: 1; /* 确保 .is-bg 及其子元素位于 ::after 伪元素的上层 */
}
.is-bg::after {
	content: "";
	background-color: var(--background);
	opacity: var(--opacity);
	position: absolute;
	left: 0;
	top: 0;
	right: 0;
	bottom: 0;
	z-index: -1;
	pointer-events: none;
}
</style>
