local this = class("cellHomeLevelInfo", G_UIModuleBase)
local _homeLevelShowTpl = L_GameTpl:getHomeLevelShowTpl()

function this.bind()
  return {
    txt_level = nil,
    list_content = {
      moduleName = "pages/home/homeLevel/cellHomeLevelInfoItem"
    },
    go_new = false,
    go_curLevelBg = false,
    go_curLevel = false,
    color_bg = nil,
    go_lock = false
  }
end

function this.methods()
  return {
    list_content = {
      onClick_select = function(self, bind, pos)
        self._selectIndex = bind.index
        self:emit("onClick_select", bind, pos)
      end
    }
  }
end

function this:open()
  this.super.open(self)
  self:initCell()
end

function this:initCell()
  if not self.isBind then
    return
  end
  L_ReddotManager:registerReddot(self.bindComponents.rect_reddotNormal, string.format(L_ReddotManager.DotDef.LevelUnlockHomeContent, self.bind.level))
  local tpl = _homeLevelShowTpl:getTplById(self.bind.level)
  local tmp = _homeLevelShowTpl:getAllUnlockContent(tpl)
  local isLock = self.bind.level > L_PlayerStore:getLv()
  for _, v in pairs(tmp) do
    v.isFatherLock = isLock
  end
  self.bind.list_content:clear()
  self.bind.list_content:insert_array(tmp)
  self.bind.txt_level = tostring(self.bind.level)
  local curLv = L_PlayerStore:getLv()
  self.bind.go_curLevel = self.bind.level == curLv
  self.bind.go_curLevelBg = self.bind.level == curLv
  self.bind.go_lock = isLock
  self.bind.color_bg = isLock and C_Color(0.4150943, 0.4150943, 0.4150943, 1) or C_Color.white
  L_GameUtil.forceRebuildLayout(self.bindComponents.rect_list_item)
end

function this:clearSelect()
  if not self.isBind then
    return
  end
  for i, v in pairs(self.modules.list_content) do
    v:setSelect(false)
  end
end

function this:selectItem(type, id)
  if not self.isBind then
    return
  end
  local list = self.modules.list_content
  for i, v in pairs(list) do
    if v.bind.type == type and v.bind.id == id then
      v:onClickSelect()
    end
  end
end

return this
