// export function calculatePrice(
//   option: { price?: number; pricePercent?: number; priceRange?: string },
//   extras: { price?: number; pricePercent?: number; priceRange?: string }[]
// ): number | [number, number] {
//   const base = option.price ?? 0

//   let total = base
//   let hasRange = false
//   let min = base
//   let max = base

//   for (const ext of extras) {
//     if (ext.price !== undefined) {
//       total += ext.price
//       min += ext.price
//       max += ext.price
//     } else if (ext.pricePercent !== undefined) {
//       const delta = base * (ext.pricePercent / 100)
//       total += delta
//       min += delta
//       max += delta
//     } else if (ext.priceRange) {
//       const [rMin, rMax] = ext.priceRange.split("–").map(Number)
//       hasRange = true
//       min += rMin
//       max += rMax
//     }
//   }

//   return hasRange ? [min, max] : total
// }


type PriceSource = {
  price?: number | null
  pricePercent?: number | null
  priceRange?: string | null
}

export function calculatePrice(source: PriceSource, base: number): number {
  if (source.price != null) return source.price
  if (source.pricePercent != null) return base * (source.pricePercent / 100)
  if (source.priceRange) {
    const parts = source.priceRange.split("–").map(Number)
    const max = Math.max(...parts)
    return isNaN(max) ? 0 : max
  }
  return 0
}