local this = class("cellItemAccess", G_UIModuleBase)

function this.bind()
  return {
    txt_access = "",
    go_arrow = false,
    go_lock = false,
    alpha_content = 1,
    activeBg = true,
    color_arrow = nil,
    color_unlock = nil,
    activeLockBg = false
  }
end

function this.methods()
  return {
    onClick = function(self)
      if math.isEmpty(self.bind.systemId) then
        return
      end
      if L_JumpMgr:checkJumpFuncOpen(self.bind.systemId) then
        L_UI:close("pageInfoTip")
        L_UI:close("pageReward")
        L_UI:close("pageExplore")
        L_UI:close("pageHeroTalentInfo")
        L_UI:close("pageRuneCompose")
      end
      L_JumpMgr:jumpTo(self.bind.systemId, {
        itemId = self.bind.itemId
      })
    end
  }
end

function this:initData()
  if not self.colorType then
    self.colorType = {
      light = C_Color(1, 1, 1, 0.7),
      dark = C_Color(0, 0, 0, 0.5)
    }
    self.styleTypeEnum = {Normal = 1, Roulette = 2}
  end
  self.styleType = self.bind.styleType or self.styleTypeEnum.Normal
end

function this:refresh()
  self:initData()
  self.bind.go_lock = false
  self.bind.go_unlock = false
  self.bind.go_arrow = false
  if not math.isEmpty(self.bind.systemId) then
    local isOpen = L_JumpMgr:checkJumpFuncOpen(self.bind.systemId)
    self.bind.go_lock = not isOpen
    self.bind.go_arrow = isOpen
    if self.styleType == self.styleTypeEnum.Normal then
      self.bind.alpha_content = isOpen and 1 or 0.5
    elseif self.styleType == self.styleTypeEnum.Roulette then
      local color = isOpen and self.colorType.light or self.colorType.dark
      if color then
        self.bindComponents.img_arrow.color = color
        self.bindComponents.img_lock.color = color
        self.bindComponents.img_location.color = color
      end
      if not isOpen then
        local str = self.bind.txt_access or ""
        self.bind.txt_access = L_GameUtil.fillColor(str, "#000000")
      end
      self.bind.alpha_content = isOpen and 1 or 0.7
      self:showLockBg(not isOpen)
    end
  end
end

function this:showLockBg(isShow)
  isShow = L_CommonUtil.toBoolean(isShow)
  self.bind.activeLockBg = isShow
  self.bind.activeBg = not isShow
end

return this
