import { respath } from "../constants/respath"

export const MONTH_LIST = [
  { year: 2024, month: 12, begin: 0, dayCount: 31, icon_res: respath.trophy_12 }

  // { year: 2025, month: 1, begin: 3, dayCount: 31, icon_res: respath.trophy_01 },
  // { year: 2025, month: 2, begin: 6, dayCount: 30, icon_res: respath.trophy_02 },
  // { year: 2025, month: 3, begin: 6, dayCount: 31, icon_res: respath.trophy_03 },
  // { year: 2025, month: 4, begin: 2, dayCount: 30, icon_res: respath.trophy_04 },
  // { year: 2025, month: 5, begin: 4, dayCount: 31, icon_res: respath.trophy_05 },
  // { year: 2025, month: 6, begin: 0, dayCount: 30, icon_res: respath.trophy_06 },
  // { year: 2025, month: 7, begin: 2, dayCount: 31, icon_res: respath.trophy_07 },
  // { year: 2025, month: 8, begin: 5, dayCount: 31, icon_res: respath.trophy_08 },
  // { year: 2025, month: 9, begin: 1, dayCount: 30, icon_res: respath.trophy_09 },
  // { year: 2025, month: 10, begin: 3, dayCount: 31, icon_res: respath.trophy_10 },
  // { year: 2025, month: 11, begin: 6, dayCount: 30, icon_res: respath.trophy_11 },
  // { year: 2025, month: 12, begin: 1, dayCount: 31, icon_res: respath.trophy_12 },

  // { year: 2026, month: 1, begin: 4, dayCount: 31, icon_res: respath.trophy_01 },
  // { year: 2026, month: 2, begin: 0, dayCount: 30, icon_res: respath.trophy_02 },
  // { year: 2026, month: 3, begin: 0, dayCount: 31, icon_res: respath.trophy_03 },
  // { year: 2026, month: 4, begin: 3, dayCount: 30, icon_res: respath.trophy_04 },
  // { year: 2026, month: 5, begin: 5, dayCount: 31, icon_res: respath.trophy_05 },
  // { year: 2026, month: 6, begin: 1, dayCount: 30, icon_res: respath.trophy_06 },
  // { year: 2026, month: 7, begin: 3, dayCount: 31, icon_res: respath.trophy_07 },
  // { year: 2026, month: 8, begin: 6, dayCount: 31, icon_res: respath.trophy_08 },
  // { year: 2026, month: 9, begin: 2, dayCount: 30, icon_res: respath.trophy_09 },
  // { year: 2026, month: 10, begin: 4, dayCount: 31, icon_res: respath.trophy_10 },
  // { year: 2026, month: 11, begin: 0, dayCount: 30, icon_res: respath.trophy_11 },
  // { year: 2026, month: 12, begin: 2, dayCount: 31, icon_res: respath.trophy_12 }
]

export function G_getMonthInfo(year: number, month: number): any {
  for (let i = 0; i < MONTH_LIST.length; i++) {
    const obj = MONTH_LIST[i]
    if (obj.year === year && obj.month === month) {
      return obj
    }
  }
  return null
}

export class DCManager {
  private static instance: DCManager
  public static getInstance(): DCManager {
    if (!DCManager.instance) {
      DCManager.instance = new DCManager()
    }
    return DCManager.instance
  }

  public init(): void {
    const trophys: Array<string> = []
    trophys.push(respath.trophy_01)
    trophys.push(respath.trophy_02)
    trophys.push(respath.trophy_03)
    trophys.push(respath.trophy_04)
    trophys.push(respath.trophy_05)
    trophys.push(respath.trophy_06)
    trophys.push(respath.trophy_07)
    trophys.push(respath.trophy_08)
    trophys.push(respath.trophy_09)
    trophys.push(respath.trophy_10)
    trophys.push(respath.trophy_11)
    trophys.push(respath.trophy_12)

    const now = new Date()
    const nowYear = now.getFullYear()
    const nowMonth = now.getMonth() + 1
    let year = nowYear
    let month = nowMonth
    if (nowMonth === 12) {
      year++
      month = 1
    }
    for (let i = 2025; i <= year; i++) {
      let b = false
      for (let j = 1; j <= 12; j++) {
        const date1 = new Date(`${i}/${j}/1`)
        let date2 = new Date(`${i}/${j + 1}/1`)
        if (j === 12) {
          date2 = new Date(`${i + 1}/1/1`)
        }
        const seconds = date2.getTime() - date1.getTime()
        const dayCount = Math.round(seconds / 1000 / 86400)
        const begin = date1.getDay()
        MONTH_LIST.push({ year: i, month: j, begin, dayCount, icon_res: trophys[j - 1] })
        if (i === year && j === month) {
          b = true
          break
        }
      }
      if (b) {
        break
      }
    }
  }
}
