local this = class("pageRaffleHistory", G_UIPageBase)

function this:ctor(...)
  this.super.ctor(self, ...)
  self.data = {pageNum = 1, cardPoolId = 1}
end

function this.bind()
  return {
    go_selectPool = false,
    txt_pageNum = "",
    scrollList_history = {
      moduleName = "pages/Raffle/cellHistoryItem"
    },
    scrollList_cardPool = {
      moduleName = "modulePages/cellButtonCommon"
    }
  }
end

function this.methods()
  return {
    onClick_close = function(self)
      L_UI:close(self.pageName)
    end,
    onClick_previous = function(self)
      self.data.pageNumber = math.clamp(self.data.pageNumber - 1, 1, L_RaffleStore:getHistoryPageCount(self.data.cardPoolType))
      self:refreshHistoryList()
    end,
    onClick_next = function(self)
      self.data.pageNumber = math.clamp(self.data.pageNumber + 1, 1, L_RaffleStore:getHistoryPageCount(self.data.cardPoolType))
      self:refreshHistoryList()
    end,
    scrollList_cardPool = {
      onClick = function(self)
        self.data.cardPoolType = self.bindComponents.cardPool_dropDown.value + 1
        self.data.pageNumber = 1
        self:refreshHistoryList()
      end
    }
  }
end

function this:preOpen(options)
  this.super.preOpen(self, options)
end

function this:close(options)
  this.super.close(self, options)
end

function this:initPage()
  self.data.pageNum = 1
  self:initPoolList()
  self:initHistoryList()
end

function this:initPoolList()
end

function this:initHistoryList()
end

function this:refreshHistoryList()
  local pageList = L_RaffleStore:getHistoryListByParam(self.data.pageNumber, self.data.cardPoolType)
  self.bind.pageNumberTxt = string.format("%s/%s", self.data.pageNumber, L_RaffleStore:getHistoryPageCount(self.data.cardPoolType))
  self.bind.historyList:clear()
  local tmp_list = {}
  local gachaTpl = L_GameTpl:getGachaTpl()
  for _, v in pairs(pageList) do
    local item = L_ItemManager:parseItem(v.propType, v.propId)
    table.insert(tmp_list, {
      cardIconPath = item.icon,
      cardQualityAndNameTxt = string.format("%s %s", L_Const.qualityToWord[item.quality], item.name),
      cardPoolNameTxt = gachaTpl:getGachaName(gachaTpl:getTplById(v.cardPoolId)),
      raffleTimeTxt = L_TimeUtil.getDisplayTime(v.time, 1),
      raffleTimeNum = v.time
    })
  end
  self.bind.historyList:insert_array(tmp_list)
end

return this
