local this = class("cellMiniPos", G_UIModuleBase)
local iconMap = {
  playerPet = 0,
  enemyPet = 1,
  player = 2,
  enemy = 3,
  playerTower = 4,
  enemyTower = 5
}

function this.bind()
  return {selectTabId = 0}
end

function this.methods()
  return {}
end

function this:open()
end

function this:close()
end

function this:refresh()
  if not self.isBind then
    return
  end
  if self.bind.selectTabId == iconMap.player then
    self:refreshPlayerNodePos()
    return
  end
  if self.bind.selectTabId == iconMap.enemy then
    self:refreshEnemyNodePos()
    return
  end
  self:setPos()
end

function this:setPos()
  if not self.isBind then
    return
  end
  if not self.bindComponents or not self.bindComponents.trans then
    return
  end
  local l2w = self.bind.mapData:worldToLocal(self.bind.entityTans.position)
  L_Vector3.setAnchored(self.bindComponents.trans, l2w)
end

function this:refreshPlayerNodePos()
  if not self.isBind then
    return
  end
  local mainControl = L_PlayerManager:getMainControlEntity()
  if mainControl == nil then
    self:setTransActive(false)
    return
  end
  self:setTransActive(true)
  local pos = mainControl:getPosition()
  local rot = mainControl:getRotation()
  local w2l = self.bind.mapData:worldToLocal(pos)
  L_Vector3.setAnchored(self.bindComponents.trans, w2l)
  L_Vector3.setRot(self.bindComponents.playerDir, L_Vector3.getTemp(0, 0, -rot.y + self.bind.mapData.zRot))
end

function this:setTransActive(isActive)
  self.bindComponents.trans.gameObject:SetActive(isActive)
end

function this:refreshEnemyNodePos()
  if not self.isBind then
    return
  end
  local redPlayer = L_KiBoDuelManager:getRedPlayerControllingEntity()
  if redPlayer == nil then
    self:setTransActive(false)
    return
  end
  self:setTransActive(true)
  local pos = redPlayer.transform.position
  local rot = redPlayer.transform.rotation
  local w2l = self.bind.mapData:worldToLocal(pos)
  L_Vector3.setAnchored(self.bindComponents.trans, w2l)
  L_Vector3.setRot(self.bindComponents.enemyDir, L_Vector3.getTemp(0, 0, -rot.y + self.bind.mapData.zRot))
end

return this
