import { D2SlistType } from './D2Sarea'

// 重复的区域名称判断
export const D2checkDuplicate = (items: D2SlistType[]): string[] => {
  const nameMap: Record<string, number> = {}

  // 统计每个 name 出现的次数
  items.forEach(item => {
    const name = item.name.toUpperCase()
    nameMap[name] = (nameMap[name] || 0) + 1
  })

  // 提取重复的 name
  return Object.keys(nameMap).filter(name => nameMap[name] > 1)
}

// ------------批量生成 笛卡尔积
export const cartesianProduct = (arrays: any) => {
  return arrays.reduce(
    (acc: any, currentArray: any) =>
      acc.flatMap((prevArr: any) =>
        currentArray.map((currentItem: any) => [...prevArr, currentItem])
      ),
    [[]]
  )
}
