/**
 * 地球物理数据类型定义
 */
export const DATA_CATEGORIES = [
  {
    label: '多波束数据',
    value: 'multibeam',
    children: [
      { label: '船载多波束', value: 'ship_multibeam' },
      { label: '潜载多波束', value: 'submarine_multibeam' }
    ]
  },
  {
    label: '侧扫数据',
    value: 'sidescan',
    children: []
  },
  {
    label: '地震数据',
    value: 'seismic',
    children: [
      { label: '浅地层地震剖面数据', value: 'shallow_seismic' },
      { label: '2D地震数据', value: 'seismic_2d' },
      { label: '3D地震数据', value: 'seismic_3d' },
      { label: 'OBN地震数据', value: 'obn_seismic' }
    ]
  },
  {
    label: '重力数据',
    value: 'gravity',
    children: []
  },
  {
    label: '磁力数据',
    value: 'magnetic',
    children: [
      { label: '船载磁力', value: 'ship_magnetic' },
      { label: '潜载磁力', value: 'submarine_magnetic' }
    ]
  },
  {
    label: 'CTD数据',
    value: 'ctd',
    children: []
  },
  {
    label: 'ADCP数据',
    value: 'adcp',
    children: []
  },
  {
    label: '海底热流数据',
    value: 'heat_flow',
    children: []
  }
]

/**
 * 扁平化数据类型选项（含子类型）
 * @returns {Array<{label: string, value: string, category: string}>}
 */
export function getFlatDataTypeOptions() {
  const options = []
  DATA_CATEGORIES.forEach((category) => {
    if (category.children.length === 0) {
      options.push({
        label: category.label,
        value: category.value,
        category: category.value
      })
      return
    }
    category.children.forEach((child) => {
      options.push({
        label: child.label,
        value: child.value,
        category: category.value
      })
    })
  })
  return options
}

/**
 * 根据类型值获取显示名称
 * @param {string} typeValue
 * @returns {string}
 */
export function getDataTypeLabel(typeValue) {
  const option = getFlatDataTypeOptions().find((item) => item.value === typeValue)
  return option ? option.label : typeValue
}

/**
 * 根据类型值获取所属大类
 * @param {string} typeValue
 * @returns {string}
 */
export function getDataCategory(typeValue) {
  const option = getFlatDataTypeOptions().find((item) => item.value === typeValue)
  return option ? option.category : ''
}
