local this = class("pageAccessoryBag", G_UIPageBase)
local TYPE_ICON = {
  [L_AccessoryConst.accessoryType.weapon] = "UI/Atlas/AccessoryPage/tex_sidebar_btn_wuqi.png",
  [L_AccessoryConst.accessoryType.coat] = "UI/Atlas/AccessoryPage/tex_sidebar_btn_yifu.png",
  [L_AccessoryConst.accessoryType.pants] = "UI/Atlas/AccessoryPage/tex_sidebar_btn_kuzi.png",
  [L_AccessoryConst.accessoryType.earring] = "UI/Atlas/AccessoryPage/tex_sidebar_btn_erhuan.png",
  [L_AccessoryConst.accessoryType.ring] = "UI/Atlas/AccessoryPage/tex_sidebar_btn_jiezhi.png"
}

function this.bind()
  return {
    module_content = {
      moduleName = "pages/accessory/moduleAccessoryBagContent"
    },
    module_content_pc = {
      moduleName = "pages/accessory/moduleAccessoryBagContent"
    }
  }
end

function this:preOpen(options)
  this.super.preOpen(self, options)
  self._selectType = options.accessoryType
  self._selectHeroGuid = options.selectHeroGuid
  L_AccessoryStore:listenCallFunc(L_AccessoryStore.event.refreshAccessoryList, self.onEvent_refreshAccessoryList, self, nil, 0)
  L_AccessoryStore:listenCallFunc(L_AccessoryStore.event.refreshAccessory, self.onEvent_refreshAccessory, self, nil, 0)
  self:initPage()
end

function this:close(options)
  this.super.close(self, options)
  L_AccessoryStore:unListenCallFunc(L_AccessoryStore.event.refreshAccessoryList, self.onEvent_refreshAccessoryList)
  L_AccessoryStore:unListenCallFunc(L_AccessoryStore.event.refreshAccessory, self.onEvent_refreshAccessory)
end

function this:initPage()
  self:initAccessoryMenu()
  self:initCommonTopModule()
  self:getContentModule():setData(self._selectHeroGuid, self._selectType)
end

function this:initCommonTopModule()
  local data = {
    name = "\230\155\191\230\141\162",
    closeCurPage = function()
      L_UI:close(self.pageName)
    end
  }
end

function this:initAccessoryMenu()
  local typeList = {
    L_AccessoryConst.accessoryType.weapon,
    L_AccessoryConst.accessoryType.coat,
    L_AccessoryConst.accessoryType.pants,
    L_AccessoryConst.accessoryType.earring,
    L_AccessoryConst.accessoryType.ring,
    L_AccessoryConst.accessoryType.shoes
  }
  local menuList = {}
  for i, v in pairs(typeList) do
    table.insert(menuList, {
      type = v,
      icon = TYPE_ICON[v]
    })
  end
  local func = function(selectType)
    self._selectType = selectType
    self:getContentModule():setData(self._selectHeroGuid, self._selectType)
  end
end

function this:onEvent_refreshAccessoryList(isDelete)
  if isDelete then
    self:getContentModule():updateAccessoryList()
  end
end

function this:onEvent_refreshAccessory(entity)
  printf("11111")
  self:getContentModule():syncAccessory()
  printf("22222")
end

function this:getContentModule()
  if L_DeviceTpl:getIsPc() then
    return self.modules.module_content_pc
  else
    return self.modules.module_content
  end
end

return this
