local GrowSellCell = class("GrowSellCell", BaseCell)
local GROW_CELL = "app/ui/shop/cell/grow_cell"
local BASE_CELL_HEIGHT = 320

function GrowSellCell:init()
    self.actGifts = {}
	local uiMap = self.baseObject:genAllChildren()
	self.scrollRectObj = uiMap["grow_sell_cell.scroll_rect"]
    self.contentObj = uiMap["grow_sell_cell.scroll_rect.viewport.content"]
    self.scrollRect = self.scrollRectObj:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
    self.scrollRect:addInitCallback(function()
        return GROW_CELL
    end)
    self.scrollRect:addRefreshCallback(function(idx, cell)
        if self.actGifts and self.actGifts[idx] then
            cell:refresh(idx, self.actGifts[idx])
        end
    end)
    self.scrollRect:clearCells()

	self.cellHeight = BASE_CELL_HEIGHT
end

function GrowSellCell:refresh()
    self.actGifts = {}
    table.insert(self.actGifts, DataManager.ShopData:getGrowUpGift())
    self.scrollRect:refillCells(#self.actGifts)

    self:getBaseObject():setSizeDeltaY(self:getCellHeight())
    self.scrollRectObj:setSizeDeltaY(self:getCellHeight())
end

function GrowSellCell:refreshTime()
    if self.scrollRect then
        if self.curCellCount ~= #self.actGifts then
            self.curCellCount = self.actGifts 
            self:refresh()
        else
            self.scrollRect:refreshAll()
        end
    end
end

function GrowSellCell:getCellCount()
    return self.actGifts and #self.actGifts or 0
end

function GrowSellCell:getCellHeight()
	return BASE_CELL_HEIGHT * self:getCellCount()
end

function GrowSellCell:getIsOpen()
	return DataManager.ShopData:hasGrowUpGift()
end

function GrowSellCell:setVisible(visible)
	self.baseObject:setVisible(visible)
end

return GrowSellCell