local this = class("moduleAccessoryAtt", G_UIModuleBase)
local _battleInfoTpl = L_GameTpl:getBattleInfoTpl()

function this.bind()
  return {
    list_att = {
      moduleName = "pages/accessory/cellAccessoryAtt"
    }
  }
end

function this:initModule(guid, ignoreMain)
  local serverData = L_AccessoryStore:getAccessory(guid)
  local att = L_AccessoryManager:getPackAtt(serverData)
  local tmp = {}
  local showBg = false
  if not ignoreMain then
    local main_att = att.mainAtt
    showBg = true
    table.insert(tmp, {
      txt_desc = string.concat(main_att.showName, "+", _battleInfoTpl:getShowTxt(main_att.attId[1], main_att.value)),
      go_bg = showBg
    })
  end
  local sub_att = att.subAtt
  for i, v in pairs(sub_att) do
    showBg = not showBg
    table.insert(tmp, {
      txt_desc = v.desc,
      alpha_canvas = v.lock and 0.6 or 1,
      go_bg = showBg
    })
  end
  self.bind.list_att:clear()
  self.bind.list_att:insert_array(tmp)
end

function this:initModulePreview(accessoryId, ignoreMain)
  local att = L_AccessoryManager:getPackAttByConfigId(accessoryId)
  local tmp = {}
  local showBg = false
  if not ignoreMain and att.mainAtt then
    local main_att = att.mainAtt
    showBg = true
    table.insert(tmp, {
      txt_desc = string.concat(main_att.showName, "+", _battleInfoTpl:getShowTxt(main_att.attId[1], main_att.value)),
      go_bg = showBg
    })
  end
  local sub_att = att.subAtt
  for i, v in pairs(sub_att) do
    showBg = not showBg
    table.insert(tmp, {
      txt_desc = v.desc,
      alpha_canvas = v.lock and 0.6 or 1,
      go_bg = showBg
    })
  end
  self.bind.list_att:clear()
  self.bind.list_att:insert_array(tmp)
end

return this
