local ForceSkinShopCell = class("ForceSkinShopCell", BaseCell)

function ForceSkinShopCell:init()
    local uiMap = self:getUIMap()
    self.imgQlt = uiMap["force_skin_shop_cell.content.img_qlt"]
    self.imgArt = uiMap["force_skin_shop_cell.content.img_art"]
    self.nameNode = uiMap["force_skin_shop_cell.content.name"]
    self.txForceName = uiMap["force_skin_shop_cell.content.name.tx_force_name"]
    self.txSkinName = uiMap["force_skin_shop_cell.content.name.tx_skin_name"]
    self.costNode = uiMap["force_skin_shop_cell.cost"]
    self.imgCost = uiMap["force_skin_shop_cell.cost.img_cost"]
    self.txCost = uiMap["force_skin_shop_cell.cost.tx_cost"]
    self.txTips = uiMap["force_skin_shop_cell.tx_tips"]    

    self:addClickListener(function()
        ModuleManager.ForceManager:showForceSkinInfoUI(self.skinId)
    end)
end

function ForceSkinShopCell:refresh(skinId)
    self.skinId = skinId
    local forceId = DataManager.ForceData:getSkinForceId(self.skinId)
    local qlt = DataManager.ForceData:getSkinQlt(self.skinId)
    local unlock = DataManager.ForceData:isSkinUnlock(self.skinId)
    local getType = DataManager.ForceData:getSkinGetType(self.skinId)
    local canUnlock = DataManager.ForceData:canUnlockSkin(self.skinId)

    self.imgQlt:setSprite(GConst.ATLAS_PATH.UI_FORCE_SKIN, "skin_force_bg_" .. qlt)
    -- self.imgArt:setSprite(GConst.ATLAS_PATH.ICON_SKIN_FORCE_SHOP, self.skinId)
    self.txForceName:setText(DataManager.ForceData:getForceName(forceId))
    self.txSkinName:setText(DataManager.ForceData:getSkinName(self.skinId))

    if not canUnlock and not unlock then
        local param = DataManager.ForceData:getSkinGetParam(self.skinId)
        if getType == GConst.ForceConst.SKIN_GET_TYPE.SHOP then
            self.costNode:setActive(true)
            self.imgCost:setActive(false)
            self.txTips:setText(GConst.EMPTY_STRING)
            self.txCost:setAnchoredPositionX(0)
            local giftCfg = ConfigManager:getConfig("act_gift")[param[1]]
            local price = GFunc.getFormatPrice(giftCfg.recharge_id)
            self.txCost:setText(price)
        elseif getType == GConst.ForceConst.SKIN_GET_TYPE.FUNC then
            self.costNode:setActive(false)
            local func = param[1]
            local target = param[2]
            if func == 1 then
                self.txTips:setText(DataManager.ForceData:getSkinGetWay(self.skinId), target)
            else
                self.txTips:setText(GConst.EMPTY_STRING)
            end
        elseif getType == GConst.ForceConst.SKIN_GET_TYPE.ACT then
            self.costNode:setActive(false)
            self.txTips:setText(DataManager.ForceData:getSkinGetWay(self.skinId))
        elseif getType == GConst.ForceConst.SKIN_GET_TYPE.EXCHANGE then
            self.costNode:setActive(true)
            self.imgCost:setActive(true)
            self.txTips:setText(GConst.EMPTY_STRING)
            local giftCfg = ConfigManager:getConfig("act_gift")[param[1]]
            local cost = giftCfg.item_cost[1]
            local id = GFunc.getRewardId(cost)
            local num = GFunc.getRewardNum(cost)
            self.imgCost:setSprite(GFunc.getIconRes(id))
            self.txCost:setText(num)
            GFunc.centerImgAndTx(self.imgCost, self.txCost, 3)
        end
    else
        self.costNode:setActive(false)
        self.txTips:setText("<color=#9CFF75>" .. I18N:getGlobalText(I18N.GlobalConst.SKIN_FORCE_DESC_6) .. "</color>")
    end
end

return ForceSkinShopCell