local module = class("moduleGuideBar", G_UIModuleBase)

function module.bind()
  return {
    guidePoint = true,
    guidePointList = {
      moduleName = "pages/Main/guideBarPointItem"
    },
    guidePointList_mapMarks = {
      moduleName = "pages/Main/guideBarPointItem"
    }
  }
end

function module.methods()
  return {}
end

function module:created(...)
  module.super.created(self, ...)
  self.bindComponents.img_guide.uvRect = C_Rect(0, 0, 1, 1)
  self.target = C_CameraManager.mainCamera.transform
  self.currentPointNum = 0
  self.taskEntityIds = {}
end

function module:open()
  L_TaskStore:listenCallFunc(L_TaskStore.event.refreshTask, self.onEvent_taskUpdateHandle, self)
  L_TaskStore:listenCallFunc(L_TaskStore.event.setCurrentTracedTask, self.onEvent_setCurrentTracedTask, self)
  L_MapStore:listenCallFunc(L_MapStore.event.refreshTracing, self.onEvent_mapMarkTraceUpdate, self)
end

function module:show()
  self.currentPointNum = 0
end

function module:close()
  L_TaskStore:unListenCallFunc(L_TaskStore.event.refreshTask, self.onEvent_taskUpdateHandle)
  L_TaskStore:unListenCallFunc(L_TaskStore.event.setCurrentTracedTask, self.onEvent_setCurrentTracedTask)
  L_MapStore:unListenCallFunc(L_MapStore.event.refreshTracing, self.onEvent_mapMarkTraceUpdate)
end

function module:onEvent_taskUpdateHandle()
  self.currentPointNum = -1
end

function module:onEvent_setCurrentTracedTask(taskID)
end

function module:onEvent_mapMarkTraceUpdate()
  local areaId = L_AreaStore:getMapAreaId()
  if not areaId then
    return
  end
  local marks = L_MapStore:getMarkBymapId(areaId)
  self.bind.guidePointList_mapMarks:clear()
  if not marks then
    return
  end
  local tempData = {}
  for k, v in pairs(marks) do
    if L_MapStore:getTracing(v.guid) then
      table.insert(tempData, {
        guidePoint = true,
        guid = v.guid,
        guideType = L_Const.guidePointType.mapMark
      })
    end
  end
  self.bind.guidePointList_mapMarks:insert_array(tempData)
end

function module:initGuidePoints(taskEntityIds, player)
end

function module:fresh()
  if self.isBind and self.target then
    self.bindComponents.img_guide.uvRect = C_Rect(self.target.rotation.eulerAngles.y / 360 - 0.5, 0, 1, 1)
    self:setTaskTracedTarget()
    self:setMapMarkTracedPoint()
  end
end

function module:setMapMarkTracedPoint()
  for i = 1, #self.bind.guidePointList_mapMarks do
    local cell = self.bind.guidePointList_mapMarks:getItemCls(i)
    if cell then
      cell:fresh()
    end
  end
end

function module:setTaskTracedTarget()
end

function module:hideAllGuidePoint()
  for i = 1, #self.bind.guidePointList do
    if self.bind.guidePointList:getItemCls(i) then
      self.bind.guidePointList:getItemCls(i):hideGuidePoint()
    end
  end
end

return module
