<script setup>
import Investment from "./sections/Investment.vue";
import SeniorExecutive from "./sections/SeniorExecutive.vue";
import Lawsuit from "./sections/Lawsuit.vue";

const props = defineProps({
    data: {
        type: Object,
        required: true,
        default: () => ({}),
    },
});
const { data } = props;

// 投资类关系
const investRelations = ["sh", "his_sh", "lp", "his_lp"];

// 高管类关系
const managerRelations = ["tm", "his_tm"];

const totalCompanies = computed(() => {
    return data?.datalist?.length || 0;
});

// 获取投资企业记录（股东、历史股东、法人、历史法人）
const investCompanies = computed(() => {
    const datalist = data?.datalist || [];
    return datalist.filter((item) => {
        const relationships = item?.relationship || [];
        return relationships.some((r) => investRelations.includes(r));
    });
});

// 获取高管任职记录（高管、历史高管）
const managerPositions = computed(() => {
    const datalist = data?.datalist || [];
    return datalist.filter((item) => {
        const relationships = item?.relationship || [];
        return relationships.some((r) => managerRelations.includes(r));
    });
});

// 获取有涉诉风险的企业
const lawsuitCompanies = computed(() => {
    const datalist = data?.datalist || [];
    return datalist.filter((item) => {
        const lawsuit = item?.lawsuitInfo || {};
        return (
            (lawsuit.data && Object.keys(lawsuit.data).length > 0) ||
            (lawsuit.sxbzxr && lawsuit.sxbzxr.length > 0) ||
            (lawsuit.xgbzxr && lawsuit.xgbzxr.length > 0)
        );
    });
});
</script>

<template>
    <div class="pb-8">
        <!-- 投资企业记录 -->
        <Investment :data="investCompanies" />

        <!-- 高管任职记录 -->
        <SeniorExecutive :data="managerPositions" />

        <!-- 涉诉风险 -->
        <Lawsuit :data="lawsuitCompanies" :total-companies="totalCompanies" />
    </div>
</template>

<style scoped>
/* 添加过渡效果 */
.company-wrapper {
    overflow: hidden;
}

/* 添加阴影悬停效果 */
.company-wrapper > div:first-child {
    transform-origin: top;
}

/* 确保展开有足够的空间 */
.max-h-\[2000px\] {
    max-height: 2000px;
}
</style>
