// src/composables/useMenuItems.js
import { ref, computed, watch } from "vue";
import yhkhmdIcon from "@/assets/images/yhkhmd_icon.svg";
import sjsysIcon from "@/assets/images/sjsys_icon.svg"; // 手机三要素
import sfzeysIcon from "@/assets/images/sfzeys_icon.svg"; // 身份证二要素
import sjeysIcon from "@/assets/images/sjeys_icon.svg"; // 手机二要素
import sjzwscIcon from "@/assets/images/sjzwsc_icon.svg"; // 在网时长
import sjeckIcon from "@/assets/images/sjeck_icon.svg"; // 手机二次卡
import sjhmfxIcon from "@/assets/images/sjhmfx_icon.svg"; // 手机号码风险
import yhk4ysIcon from "@/assets/images/yhk4ys_icon.svg"; // 银行卡四要素
import yhksysIcon from "@/assets/images/yhksys_icon.svg"; // 银行卡三要素
import zrrscztIcon from "@/assets/images/zrrsczt_icon.svg"; // 自然人生存状态
import xlhyIcon from "@/assets/images/xlhy_icon.svg"; // 学历核验
import rchyIcon from "@/assets/images/rchy_icon.svg"; // 人车核验
import mxclIcon from "@/assets/images/mxcl_icon.svg"; // 名下车辆
import srhyIcon from "@/assets/images/srhy_icon.svg"; // 双人婚姻
import grblIcon from "@/assets/images/grbl_icon.svg";
import gdrqgxIcon from "@/assets/images/gdrqgx_icon.svg";

import carClgzIcon from "@/assets/images/car_cheliangguzhi.png";
import carClghIcon from "@/assets/images/car_cheliangguohu.png";
import carCxxxIcon from "@/assets/images/car_chexian.png";
import carCxsxIcon from "@/assets/images/car_cheliangshangxian.png";
import carCjhccIcon from "@/assets/images/car_vinchache.png";
import carWbxxIcon from "@/assets/images/car_weibao.png";

// 定义所有菜单项
const allMenuItems = [
    {
        title: "手机三要素",
        icon: sjsysIcon,
        product: "toc_PhoneThreeElements",
        description: "查询个人与手机号码是否匹配，确保手机号码的真实性。",
    },
    {
        title: "银行卡黑名单",
        icon: yhkhmdIcon,
        product: "toc_BankCardBlacklist",
        description: "查询银行卡是否被列入黑名单，帮助您识别潜在的金融风险。",
    },
    {
        title: "身份证二要素",
        icon: sfzeysIcon,
        product: "toc_IDCardTwoElements",
        description: "验证姓名与身份证号码的匹配情况，确保身份真实性。",
    },
    {
        title: "手机二要素",
        icon: sjeysIcon,
        product: "toc_PhoneTwoElements",
        description: "查询手机号码和身份证的匹配情况，用于验证身份的真实性。",
    },
    {
        title: "手机在网时长",
        icon: sjzwscIcon,
        product: "toc_NetworkDuration",
        description: "查询手机号码的在网时长，帮助评估号码的稳定性与历史。",
    },
    {
        title: "手机二次卡",
        icon: sjeckIcon,
        product: "toc_PhoneSecondaryCard",
        description: "检查手机是否有二次卡，防止诈骗等风险。",
    },
    {
        title: "手机号码风险",
        icon: sjhmfxIcon,
        product: "toc_PhoneNumberRisk",
        description: "评估手机号码的潜在风险，包括是否与违法行为关联。",
    },
    {
        title: "银行卡四要素",
        icon: yhk4ysIcon,
        product: "toc_BankCardFourElements",
        description:
            "通过四要素核验银行卡与个人是否匹配，进一步验证银行账户的真实性。",
    },
    {
        title: "自然人生存状态",
        icon: zrrscztIcon,
        product: "toc_NaturalLifeStatus",
        description: "查询个人的生存状态，帮助验证其是否真实存在。",
    },
    {
        title: "银行卡三要素",
        icon: yhksysIcon,
        product: "toc_BankCardThreeElements",
        description: "查询银行卡的三要素，验证账户信息的安全性。",
    },
    {
        title: "学历核验",
        icon: xlhyIcon,
        product: "toc_EducationVerification",
        description: "验证学历信息的真实性，确保所提供的学历符合实际。",
    },
    {
        title: "人车核验",
        icon: rchyIcon,
        product: "toc_PersonVehicleVerification",
        description: "查询个人与车辆的关联情况，帮助识别车辆的所有权和风险。",
    },
    {
        title: "名下车辆",
        icon: mxclIcon,
        product: "toc_VehiclesUnderName",
        description: "查询个人名下拥有车辆的数量，了解其车辆资产。",
    },
    {
        title: "车辆出险信息",
        icon: carCxxxIcon,
        product: "toc_vehicleInsuranceSummary",
        description:
            "车辆出险综合信息查询功能可以帮助用户全面了解车辆的出险记录和历史，提供详尽的事故和保险信息，帮助用户做出更明智的决策。",
    },
    {
        title: "车辆维保记录",
        icon: carWbxxIcon,
        product: "toc_vehicleMaintenanceRecord",
        description:
            "车辆维修保养记录查询功能可以帮助用户查看车辆的所有维修和保养历史，确保车辆的状态和性能得到全面了解。",
    },
    // {
    //     title: "车辆上险信息",
    //     icon: "sxInfoIcon",
    //     product: "toc_vehicleInsuranceInfo",
    //     description:
    //         "车辆上险信息查询功能可以帮助用户了解车辆的保险情况，包括是否已投保、保险公司及保单详情，确保车辆的风险得到保障。",
    // },
    {
        title: "车架号查车",
        icon: carCjhccIcon,
        product: "toc_chassisNumberCheck",
        description:
            "车架号查车功能帮助用户通过车辆的车架号查询车辆的详细信息，包括品牌、型号、生产年份等，有助于验证车辆的真实情况。",
    },
    {
        title: "车辆过户次数",
        icon: carClghIcon,
        product: "toc_vehicleTransferCount",
        description:
            "车辆过户次数查询功能可以帮助用户了解车辆的过户历史，提供车辆的转手记录和所有权变更情况，帮助用户判断车辆的历史背景。",
    },
    {
        title: "车辆估值",
        icon: carClgzIcon,
        product: "toc_vehicleValuation",
        description:
            "车辆估值功能帮助用户评估车辆的市场价值，提供基于车型、年限、车况等因素的估值报告，帮助用户做出购买或出售决策。",
    },
    {
        title: "双人婚姻",
        icon: srhyIcon,
        product: "toc_DualMarriage",
        description: "查询双人婚姻状况，帮助评估婚姻的法律状态和风险。",
    },
    {
        title: "个人不良",
        icon: grblIcon,
        product: "toc_PersonalBadRecord",
        description:
            "通过查询个人的不良记录，评估其风险等级（低、中、高风险）。帮助您识别潜在的信用和法律风险，确保合作方的合法合规。",
    },
    {
        title: "人企关系",
        icon: gdrqgxIcon,
        product: "toc_ShareholderBusinessRelation",
        description:
            "通过个人关联的企业，了解其可能涉及的风险，帮助您判断该个人的风险水平，特别是与高风险企业有联系的个人。",
    },
];

// 定义 Composable，返回过滤后的菜单项
export function useMenuItems() {
    const availableProducts = ref([]);
    const requestUrl = ref(`/product/render_list/`);
    const { data, error, execute, isFetching, onFetchResponse } = useApiFetch(
        requestUrl,
        { immediate: false, refetch: true }
    )
        .get()
        .json();

    onFetchResponse((response) => {
        if (data.value && !error.value) {
            if (data.value.code === 200) {
                availableProducts.value = data.value.data.Product.map(
                    (product) => product.product_en
                );
                console.log("allMenuItems");
            }
        }
    });

    // fetchRenderData 支持外部传入 verify 参数
    const fetchRenderData = async (verifyParam) => {
        requestUrl.value = `/product/render_list/${verifyParam}`;
        // execute()
    };

    // 返回过滤后的菜单项
    const availableMenuItems = computed(() => {
        return allMenuItems.filter((item) =>
            availableProducts.value.includes(item.product)
        );
    });

    return {
        fetchRenderData,
        availableMenuItems,
        isFetching,
    };
}
