local SkinCell = class("SkinCell", BaseCell)


function SkinCell:init()
    local uiMap = self:getUIMap()
    self.spineRoot = uiMap["skin_cell.spine_root.spine_hero"]
    self.bgQlt = uiMap["skin_cell.bg_qlt"]
    self.imgQlt = uiMap["skin_cell.bg_qlt.img_qlt"]
    self.select = uiMap["skin_cell.select"]
    self.imgS = uiMap["skin_cell.img_s"]

    self:addClickListener(function()
        EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.SKIN_SELECT, self.skinId)
    end)
end

function SkinCell:refresh(id, isSelect)
    self.skinId = id
    local cfg = DataManager.SkinData:getSkinCfg(self.skinId)

    SpineManager:loadHeroAsync(DataManager.SkinData:getModelId(self.skinId), self.spineRoot, function(spineObject)
        if self.spineHero then
            self.spineHero:destroy()
            self.spineHero = nil
        end
        spineObject:setDefaultMix(0)
        self.spineHero = spineObject
    end)

    local qlt = cfg.qlt

    self.imgS:setActive(qlt >= 4)
    self.select:setActive(isSelect)
    self.baseObject:setSprite(GConst.ATLAS_PATH.HERO, "hero_skin_frame_".. qlt .. "_1")
    self.bgQlt:setSprite(GConst.ATLAS_PATH.HERO, "hero_frame_bg_".. qlt)
    self.imgQlt:setSprite(GConst.ATLAS_PATH.HERO, "hero_skin_" .. qlt)
end

return SkinCell