local this = class("moduleCurrency", G_UIModuleBase)
local _systemUnlockTpl = L_GameTpl:getSystemUnlockTpl()

function this.bind()
  return {
    resList = {
      moduleName = "modulePages/cellCurrency"
    }
  }
end

function this:open()
  this.super.open(self)
  L_PlayerStore:listenCallFunc(L_PlayerStore.event.refreshAttr, self.onEvent_refreshResHandle, self)
  L_BagStore:listenCallFunc(L_BagStore.event.refreshBag, self.onEvent_refreshResHandle, self)
end

function this:close()
  this.super.close(self)
  L_PlayerStore:unListenCallFunc(L_PlayerStore.event.refreshAttr, self.onEvent_refreshResHandle)
  L_BagStore:unListenCallFunc(L_BagStore.event.refreshBag, self.onEvent_refreshResHandle)
end

function this:refreshRes(tpl_system)
  if table.isEmpty(tpl_system) then
    self.bind.resList:clear()
    return
  end
  local res = _systemUnlockTpl:getResourceBar(tpl_system)
  local tmp = {}
  self.bind.resList:clear()
  for _, resId in ipairs(res) do
    table.insert(tmp, {resId = resId})
  end
  self.bind.resList:insert_array(tmp)
end

function this:refreshResByResBarTplIdList(resBarTplIdList)
  if table.isEmpty(resBarTplIdList) then
    self.bind.resList:clear()
    return
  end
  local tmp = {}
  self.bind.resList:clear()
  for _, resBarTplId in ipairs(resBarTplIdList) do
    table.insert(tmp, {resId = resBarTplId})
  end
  self.bind.resList:insert_array(tmp)
end

function this:onEvent_refreshResHandle(attr)
  for _, module in ipairs(self.modules.resList) do
    module:refreshNum()
  end
end

return this
