local BattleDailyChallengeBuffUI = class("BattleDailyChallengeBuffUI", BaseUI)

function BattleDailyChallengeBuffUI:isFullScreen()
    return false
end

function BattleDailyChallengeBuffUI:getPrefabPath()
    return "assets/prefabs/ui/battle/battle_daily_challenge_buff_ui.prefab"
end

function BattleDailyChallengeBuffUI:ctor()
    self.buffDescs = {}
    for _, id in ipairs(DataManager.DailyChallengeData:getTodayBuffIds()) do
        local cfg = ConfigManager:getConfig("buff_daily_challenge")[id]
        if cfg then
            self.buffDescs[cfg.buff_type] = ModuleManager.DailyChallengeManager:getBuffDesc(id)
        end
    end
end

function BattleDailyChallengeBuffUI:onClose()
    if self.txSeq then
        self.txSeq:Kill()
        self.txSeq = nil
    end
end

function BattleDailyChallengeBuffUI:onLoadRootComplete()
    self:_display()
    self:_addListeners()
end

function BattleDailyChallengeBuffUI:_display()
    local uiMap = self.root:genAllChildren()
    local buffDescs = {
        uiMap["battle_daily_challenge_buff_ui.raw_img.desc_1"],
        uiMap["battle_daily_challenge_buff_ui.raw_img.desc_2"]
    }
    for index, obj in ipairs(buffDescs) do
        obj:setText(self.buffDescs[index])
    end
    local txNode = uiMap["battle_daily_challenge_buff_ui.raw_img"]:getComponent(GConst.TYPEOF_UNITY_CLASS.CANVAS_GROUP)
    txNode.alpha = 0
    local spineObj = uiMap["battle_daily_challenge_buff_ui.ui_spine_obj"]
    spineObj:setVisible(false)

    if self.txSeq then
        self.txSeq:Kill()
        self.txSeq = nil
    end
    self.txSeq = self.root:createBindTweenSequence()
    self.txSeq:AppendInterval(0.2)
    self.txSeq:AppendCallback(function()
        spineObj:setVisible(true)
        spineObj:playAnim("idle", false, true)
    end)
    self.txSeq:AppendInterval(0.2)
    self.txSeq:Append(txNode:DOFade(1, 0.2))
end

function BattleDailyChallengeBuffUI:_addListeners()
    local uiMap = self.root:genAllChildren()
    uiMap["battle_daily_challenge_buff_ui.mask"]:addClickListener(function()
        self:closeUI()
    end)
end

return BattleDailyChallengeBuffUI