<template>
    <div class="flex items-center justify-center card">
        <div class="max-w-md w-full p-4">
            <!-- 核验结果 -->
            <h3 class="text-xl font-semibold text-gray-700 mb-4">
                婚姻核验结果
            </h3>
            <div
                :class="[
                    'mb-6 p-2 rounded-3xl text-lg font-medium text-center text-white shadow-lg',
                    getStatusClass(data.status),
                ]"
            >
                {{ getStatusText(data.status) }}
            </div>
            <div class="text-sm text-gray-600">
                <p>{{ statusDescription(data.status) }}</p>
            </div>
        </div>
    </div>
</template>

<script setup>
const props = defineProps({
    data: {
        type: Object,
        required: true,
    },
    params: {
        type: Object,
        required: true,
    },
});

const { data } = toRefs(props);
// 状态背景色和图标
const getStatusClass = (status) => {
    const statusClassMapping = {
        0: "bg-yellow-500",
        1: "bg-green-600",
        2: "bg-red-500",
        3: "bg-blue-400",
    };
    return statusClassMapping[status] || "bg-gray-500";
};

// 核验状态描述
const getStatusText = (status) => {
    const statusMapping = {
        0: "无婚姻关系",
        1: "已婚",
        2: "已离婚",
        3: "离婚冷静期",
    };
    return statusMapping[status] || "未知状态";
};

const statusDescription = (status) => {
    const descriptionMapping = {
        1: "双方是夫妻关系，目前处于已婚状态。",
        2: "双方存在过婚姻关系，目前已离婚。",
        3: "双方目前处于离婚冷静期。",
        0: "双方不存在婚姻关系。",
    };
    return descriptionMapping[status] || "无详细描述。";
};

// 对请求参数进行脱敏处理
const maskValue = (value, type) => {
    if (type === "name") {
        // 姓名脱敏（保留首位）
        return value.length > 1 ? value[0] + "*".repeat(value.length - 1) : "*";
    } else if (type === "id_card") {
        // 身份证号脱敏（保留前6位和最后4位）
        return value.replace(/^(.{6})(?:\d+)(.{4})$/, "$1****$2");
    }
    return value;
};

const maskedParams = {
    nameMan: maskValue(props.params.nameMan, "name"),
    idCardMan: maskValue(props.params.idCardMan, "id_card"),
    nameWoman: maskValue(props.params.nameWoman, "name"),
    idCardWoman: maskValue(props.params.idCardWoman, "id_card"),
};
</script>

<style scoped></style>
