<template>
	<div class="fix-line is-bg" :style="baseStyle">
		<div class="inner" :style="innerStyle"></div>
	</div>
</template>

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

const props = defineProps({
	mode: {
		type: String,
		default: "solid"
	},
	color: {
		type: String,
		default: "#f5f6fa"
	},
	height: {
		type: Number,
		default: 4
	},
	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`
	};
});
const innerStyle = computed(() => {
	return {
		borderBottom: `${props.height / 2}px ${props.mode} ${props.color}`
	};
});
</script>

<style lang="scss" scoped>
.fix-line {
	box-sizing: border-box;
	overflow: hidden;
}
.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>
