local PageBtnsComp = class("PageBtnsComp", LuaComponent)

local PAGE_BTN_CELL = "app/ui/activity/common/cell/act_page_btn_cell"

function PageBtnsComp:init()
    local uiMap = self:getUIMap()
    self.scrollrect = uiMap["act_page_btns_comp.scrollrect"]
    self.content = uiMap["act_page_btns_comp.scrollrect.viewport.content"]
end

function PageBtnsComp:setRedPointPos(posX, posY, scale)
    self.redPosX = posX
    self.redPosY = posY
    self.redScale = scale
end

function PageBtnsComp:refresh(list, index)
    self.list = list or {}
    if not self.scrollRect then
        self.scrollRect = self.scrollrect:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
        self.scrollRect:addInitCallback(function()
            return PAGE_BTN_CELL
        end)
        self.scrollRect:addRefreshCallback(function(index, cell)
            cell:setRedPointPos(self.redPosX, self.redPosY, self.redScale)
            cell:refresh(self.list[index])
        end)
    end
    if self.scrollRect:getTotalCount() == nil or self.scrollRect:getTotalCount() <= 0 then
		self.scrollRect:refillCells(#self.list)
    elseif self.scrollRect:getTotalCount() ~= #self.list then
		self.scrollRect:clearCells()
		self.scrollRect:refillCells(#self.list)
	else
		self.scrollRect:updateAllCell()
	end
    if index then
        self.scrollRect:moveToIndex(index)
    end
    local maxSizeX = math.min(#self.list * 124, 540)
    self.baseObject:setSizeDeltaX(#self.list * 124)
    self.content:setSizeDeltaX(#self.list * 124)
end

return PageBtnsComp