local this = class("pageRaffleUpInfo", G_UIPageBase)
local _gachaTpl = L_GameTpl:getGachaTpl()

function this:ctor(...)
  this.super.ctor(self, ...)
  self.data = {curPoolId = nil}
end

function this.bind()
  return {
    scrollList_ssr = {
      moduleName = "pages/Raffle/cellRaffleUpItem"
    },
    scrollList_sr = {
      moduleName = "pages/Raffle/cellRaffleUpItem"
    }
  }
end

function this.methods()
  return {
    onClick_close = function(self)
      L_UI:close(self.pageName)
    end,
    scrollList_ssr = {
      onClick_select = function(self, bind)
        local data = bind.parseData
        self:showPreviewPanel(data)
      end
    },
    scrollList_sr = {
      onClick_select = function(self, bind)
        local data = bind.parseData
        self:showPreviewPanel(data)
      end
    }
  }
end

function this:showPreviewPanel(data)
  local itemType = data.itemType
  if itemType == L_Const.resType.hero then
    local entityId = data.itemID
    local list = {}
    table.insert(list, entityId)
    L_UI:open("pageHero", {
      heroIdList = list,
      pageType = L_Const.heroPageType.PreviewMode
    })
  elseif itemType == L_Const.resType.spiritron then
    local entityId = L_GameUtil.getDefaultHeroId()
    local list = {}
    table.insert(list, entityId)
    L_UI:open("pageHero", {
      spiritronId = data.itemID,
      heroIdList = list,
      pageType = L_Const.heroPageType.SpritronPreviewMode
    })
  end
end

function this:preOpen(options)
  this.super.preOpen(self, options)
  self.data.curPoolId = options.poolId
  self:initPage()
end

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

function this:initPage()
  self:initList()
end

function this:initList()
  local gachaTpl = L_GameTpl:getGachaTpl()
  local tpl = gachaTpl:getTplById(self.data.curPoolId)
  local upList = gachaTpl:getUpStuff(tpl)
  local tmp = {}
  for _, v in pairs(upList) do
    local item = L_ItemManager:parseItem(v[1], v[2])
    table.insert(tmp, {
      parseData = item,
      img_icon = item.icon,
      img_quality = item.imgQuality,
      txt_name = item.name
    })
  end
  local ssr = {}
  local sr = {}
  for i, v in pairs(tmp) do
    if v.parseData.quality == L_Const.quality.ssr then
      table.insert(ssr, v)
    elseif v.parseData.quality == L_Const.quality.sr then
      table.insert(sr, v)
    end
  end
  self.bind.scrollList_ssr:clear()
  self.bind.scrollList_ssr:insert_array(ssr)
  self.bind.scrollList_sr:clear()
  self.bind.scrollList_sr:insert_array(sr)
end

return this
