local BaseTipsUI = class("BattleSkillTips", BaseUI)

function BaseTipsUI:isFullScreen()
    return false
end

function BaseTipsUI:getType()
    return UIManager.UI_TYPE.MULTI
end

---- params = {tipsCompPrefabPath = ?, tipsCompLuaPath = ?, tipsCompParams = ?}
function BaseTipsUI:ctor(params)
    self.curTipsCompPrefabPath = params.tipsCompPrefabPath
    self.curTipsCompLuaPath = params.tipsCompLuaPath
    self.curTipsCompParams = params.tipsCompParams
end

function BaseTipsUI:getPrefabPath()
    return "assets/prefabs/ui/tips/base_tips_ui.prefab"
end

function BaseTipsUI:onLoadRootComplete()
    self:clearSubComps()
    if not self.root.__tipsComps then
        self.root.__tipsComps = {}
    end
    if self.root.__tipsComps[self.curTipsCompLuaPath] then
        self.root.__tipsComps[self.curTipsCompLuaPath]:getBaseObject():setActive(true)
        self.root.__tipsComps[self.curTipsCompLuaPath]:refresh(self.curTipsCompParams)
    else
        UIPrefabManager:loadUIWidgetAsync(self.curTipsCompPrefabPath, self.root, function(prefabObject)
            if prefabObject:getAssetPath() ~= self.curTipsCompPrefabPath then
                prefabObject:destroy()
                return
            end

            prefabObject:initPrefabHelper()
            prefabObject:genAllChildren()
            self.root.__tipsComps[self.curTipsCompLuaPath] = prefabObject:addLuaComponent(self.curTipsCompLuaPath)
            self.root.__tipsComps[self.curTipsCompLuaPath]:refresh(self.curTipsCompParams)
        end)
    end

     self.root:addClickListener(function()
        self:closeUI()
    end)
end

function BaseTipsUI:clearSubComps()
    if not self.root.__tipsComps then
        return
    end
    for path, comp in pairs(self.root.__tipsComps) do
        comp:onUIClose()
        comp:getBaseObject():setActive(false)
    end
end

function BaseTipsUI:onClose()
    self:clearSubComps()
end

return BaseTipsUI