/*
 * @Author: donghao donghao@supervision.ltd
 * @Date: 2025-06-12 11:26:49
 * @LastEditors: donghao donghao@supervision.ltd
 * @LastEditTime: 2025-06-12 14:33:40
 * @FilePath: \Web-Traffic-Police\src\views\dataView\hooks\useAll.ts
 * @Description: 处理数据
 */

import { sw } from "element-plus/es/locale";

export const useAllData = () => {
  // 数据项
  interface ListItem {
    titles: string[];
    video_url: string;
  }

  const typeMap = {
    "1": [
      "递钱",
      "递烟",
      "遮挡",
      "人机分离",
      "视频损坏",
      "遮挡车牌",
      "酒精度数",
      "逃避酒精检测",
      "过激行为",
      "语音角色",
      "多次吹气",
      "视频质量检测",
    ],
    "3": ["目标检测"],
    "2": ["车牌识别", "人脸检测"],
    "4": ["音频检测"],
    
  };

  // 去重生成目录
  const filterMenuByData = (data: ListItem[]): string[] => {
    // 合并所有titles数组
    const allTitles = data.flatMap((item) => item.titles);
    // 去重
    const uniqueTitles = Array.from(new Set(allTitles));
    return uniqueTitles;
  };

  // 根据所选title筛选相关数据
  const filterDetailsByData = (
    data: ListItem[],
    selectedTitle: string
  ): ListItem[] => {
    return data.filter((item) => item.titles.includes(selectedTitle));
  };

  // 根据title归类
  const fetchTypeByTitle = (title: string): string => {
    return Object.entries(typeMap).find(([_, titles]) => 
      titles.includes(title)
    )?.[0]; // 使用可选链避免undefined错误
  };

  return {
    filterMenuByData,
    filterDetailsByData,
    fetchTypeByTitle
  };
};
