local DungeonRuneRebirthUI = class("DungeonRuneRebirthUI", BaseUI)

function DungeonRuneRebirthUI:isFullScreen()
    return false
end

function DungeonRuneRebirthUI:getPrefabPath()
    return "assets/prefabs/ui/dungeon_rune/dungeon_rune_rebirth_ui.prefab"
end

function DungeonRuneRebirthUI:ctor(params)
    self.runeData = DataManager.DungeonData:getDungeonDataByType(ModuleManager.MODULE_KEY.RUNES_OPEN)
    self.adCallback = params.adCallback
    self.refuseCallback = params.refuseCallback
    self.isHpOver = params.isHpOver
    self.roundIsOver = params.roundIsOver
end

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

function DungeonRuneRebirthUI:_display()
    local uiMap = self.root:genAllChildren()
    uiMap["dungeon_rune_rebirth_ui.title_bg_img.title_text"]:setText(I18N:getGlobalText(I18N.GlobalConst.DUNGEON_RUNE_TIP_2))
    local desc1
    local desc2
    if self.isHpOver then
        desc1 = I18N:getGlobalText(I18N.GlobalConst.DUNGEON_RUNE_TIP_6)
        desc2 = I18N:getGlobalText(I18N.GlobalConst.DUNGEON_RUNE_TIP_4)
        if self.roundIsOver then
            desc1 = I18N:getGlobalText(I18N.GlobalConst.DUNGEON_RUNE_TIP_3)
        end
    else
        desc1 = I18N:getGlobalText(I18N.GlobalConst.DUNGEON_RUNE_TIP_3)
        desc2 = I18N:getGlobalText(I18N.GlobalConst.DUNGEON_RUNE_TIP_5)
    end
    uiMap["dungeon_rune_rebirth_ui.title_bg_img.content_tx"]:setText(desc1)
    uiMap["dungeon_rune_rebirth_ui.title_bg_img.content_tx_2"]:setText(desc2)
    uiMap["dungeon_rune_rebirth_ui.title_bg_img.desc_close"]:setText(I18N:getGlobalText(I18N.GlobalConst.DUNGEON_RUNE_DESC_7))

    local freeObj = uiMap["dungeon_rune_rebirth_ui.title_bg_img.ok_btn.text"]
    freeObj:setText(I18N:getGlobalText(I18N.GlobalConst.STR_FREE))
    local freeAd = uiMap["dungeon_rune_rebirth_ui.title_bg_img.ok_btn.icon"]
    GFunc.centerImgAndTx(freeAd, freeObj, 5)
end

function DungeonRuneRebirthUI:_addListeners()
    local uiMap = self.root:genAllChildren()
    uiMap["dungeon_rune_rebirth_ui.title_bg_img.desc_close"]:addClickListener(function()
        self:closeUI()
        local callback = self.refuseCallback
        self.refuseCallback = nil
        if callback then
            callback()
        end
    end)

    uiMap["dungeon_rune_rebirth_ui.title_bg_img.ok_btn"]:addClickListener(function()
        SDKManager:showFullScreenAds(BIReport.ADS_CLICK_TYPE.DUNGEON_RUNE_REBIRTH, function()
            ModuleManager.DungeonRuneManager:reqRebirth(self.isHpOver)
        end)
    end)

    self:addEventListener(EventManager.CUSTOM_EVENT.BATTLE_REBIRTH, function()
        self:closeUI()
        local callback = self.adCallback
        self.adCallback = nil
        if callback then
            callback()
        end
    end)
end

return DungeonRuneRebirthUI