local ActBossRushPopUI = class("ActBossRushPopUI", BaseUI)

function ActBossRushPopUI:onPressBackspace()
	self:closeUI()
end

function ActBossRushPopUI:isFullScreen()
    return false
end

function ActBossRushPopUI:getPrefabPath()
    return "assets/prefabs/ui/activity/act_boss_rush/act_boss_rush_pop_ui.prefab"
end

function ActBossRushPopUI:onClose()
    if self.popCheckBar then
        self.popCheckBar:saveCheckStatus()
    end
end

function ActBossRushPopUI:onLoadRootComplete()
    self:_display()
    self:_addListeners()

    self:refreshTime()
    if self.actCountdownSid then
        self:unscheduleGlobal(self.actCountdownSid)
    end
    self.actCountdownSid = self:scheduleGlobal(function()
        self:refreshTime()
	end, 1)

    DataManager.ActBossRushData:markPoped()
end

function ActBossRushPopUI:_display()
    local uiMap = self.root:genAllChildren()
    uiMap["act_boss_rush_pop_ui.ui_spine_obj"]:playAnim("idle", true, false)
    uiMap["act_boss_rush_pop_ui.ui_spine_obj.title"]:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_BOSS_RUSH_DESC_2))
    uiMap["act_boss_rush_pop_ui.ui_spine_obj.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_BOSS_RUSH_DESC_13))
    uiMap["act_boss_rush_pop_ui.btn_goto.tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.ACT_BOSS_RUSH_DESC_14))

    self.popCheckBar = uiMap["act_boss_rush_pop_ui.pop_check_bar"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.POP_CHECK_BAR)
    self.popCheckBar:refresh(false, "ActBossRushData")
end

function ActBossRushPopUI:_addListeners()
    local uiMap = self.root:genAllChildren()
    uiMap["act_boss_rush_pop_ui.close_btn"]:addClickListener(function()
        self:closeUI()
    end)

    uiMap["act_boss_rush_pop_ui.btn_goto"]:addClickListener(function()
        if not DataManager.ActBossRushData:getIsOpen() then
            GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ACTIVITY_OVER_EDSC))
            return
        end
        ModuleManager.ActBossRushManager:showMainUI()
        self:closeUI()
    end)
end

function ActBossRushPopUI:refreshTime()
    local uiMap = self.root:genAllChildren()
    local remainTime = DataManager.ActBossRushData:getRemainTime()
    local str
    if remainTime <= 0 then
        str = I18N:getGlobalText(I18N.GlobalConst.ACTIVITY_OVER_EDSC)
    else
        str = Time:formatNumTimeStr(remainTime)
    end
    uiMap["act_boss_rush_pop_ui.ui_spine_obj.countdown.tx_countdown"]:setText(str)
end

return ActBossRushPopUI