local this = class("moduleDuelResultNotify", G_UIModuleBase)
local petTpl = L_GameTpl:getPetTpl()
local duelKoTpl = L_GameTpl:getKiboDuelKoTpl()
local _, winColor = C_ColorUtility.TryParseHtmlString("#4C9AFF")
local _, loseColor = C_ColorUtility.TryParseHtmlString("#FF5B5C")
local continuousKillDescIds = L_Config:getConfig("game", "KIBO_DUEL_CONTINUITY_KO_BROADCAST")
local multiKillDescIds = L_Config:getConfig("game", "KIBO_DUEL_ACCUMULATE_KO_BROADCAST")
local multiKillRepeatDesc = L_Config:getConfig("game", "KIBO_DUEL_ACCUMULATE_KO_REPEAT_NUM")
local shutDownDescId = L_Config:getConfig("game", "KIBO_DUEL_ACCUMULATE_KO_OVER_BROADCAST")
local continuousKillStart = L_Config:getConfig("game", "KIBO_DUEL_CONTINUITY_KO_NUM")
local multiKillStart = L_Config:getConfig("game", "KIBO_DUEL_ACCUMULATE_KO_NUM")

function this.bind()
  return {
    img_winPetIcon = "",
    img_losePetIcon = "",
    winCircleColor = winColor,
    winRingColor1 = winColor,
    winRingColor2 = winColor,
    winBgGlowColor = winColor,
    loseCircleColor = loseColor,
    loseRingColor1 = loseColor,
    loseRingColor2 = loseColor,
    loseBgGlowColor = loseColor,
    iconGlowColor = winColor,
    txt_killNotify = "",
    multiKillFireActive = false
  }
end

function this.methods()
  return {}
end

function this:playResultNotify(data)
  local targetColor = data.isWin and winColor or loseColor
  local oppositeColor = data.isWin and loseColor or winColor
  self.bind.winCircleColor = targetColor
  self.bind.winRingColor1 = targetColor
  self.bind.winRingColor2 = targetColor
  self.bind.winBgGlowColor = targetColor
  self.bind.loseCircleColor = oppositeColor
  self.bind.loseRingColor1 = oppositeColor
  self.bind.loseRingColor2 = oppositeColor
  self.bind.loseBgGlowColor = oppositeColor
  self.bind.iconGlowColor = targetColor
  local enemyTpl = petTpl:getTplById(data.enemy.petConfigId)
  local playerTpl = petTpl:getTplById(data.player.petConfigId)
  if data.isWin then
    self.bind.img_winPetIcon = petTpl:getPetIcon(playerTpl, self:petIsSpecial(data.player.guid))
    self.bind.img_losePetIcon = petTpl:getPetIcon(enemyTpl, self:petIsSpecial(data.enemy.guid))
  else
    self.bind.img_winPetIcon = petTpl:getPetIcon(enemyTpl, self:petIsSpecial(data.enemy.guid))
    self.bind.img_losePetIcon = petTpl:getPetIcon(playerTpl, self:petIsSpecial(data.player.guid))
  end
  if data.isShutDown and (data.multiNotifyState == L_Const.kiboDuelMultiNotifyEnum.shutDown or data.multiNotifyState == nil) then
    self.bind.txt_killNotify = duelKoTpl:getDesc(duelKoTpl:getTplById(shutDownDescId))
  elseif continuousKillDescIds[data.continuousKillCount] then
    local descId = continuousKillDescIds[data.continuousKillCount]
    local desc = duelKoTpl:getDesc(duelKoTpl:getTplById(descId))
    self.bind.txt_killNotify = desc
  elseif data.killCount >= multiKillStart then
    local isRepeat = multiKillDescIds[data.killCount] == nil
    local descId = isRepeat and multiKillRepeatDesc or multiKillDescIds[data.killCount]
    local desc = duelKoTpl:getDesc(duelKoTpl:getTplById(descId))
    self.bind.txt_killNotify = desc
  else
    self.bind.txt_killNotify = L_WordsTpl:getValue("ui_moduleDuelResultNotify")
  end
  self.bind.multiKillFireActive = data.killCount >= multiKillStart
end

function this:petIsSpecial(guid)
  if guid then
    local petItem = L_PetStore:getPetItem(guid)
    if petItem then
      return petItem:isSpecialPet()
    end
  end
  return false
end

return this
