local this = class("cellTeamBtnAdd", G_UIModuleBase)
local _screenPosToUI = Unity.RectTransformUtility.ScreenPointToLocalPointInRectangle

function this.bind()
  return {
    txt_posIndex = nil,
    isOn_switchPos = false,
    isOn_addPet = false
  }
end

function this.methods()
  return {
    onClick_addHero = function(self)
      self:emit("onClick_addHero", self.bind)
    end,
    onClick_addPet = function(self)
      self:emit("onClick_addPet", self.bind)
    end,
    onClick_addSwitchPos = function(self)
      self:emit("onClick_addSwitchPos", self.bind)
    end
  }
end

function this:open()
  self:initCell()
end

function this:initCell()
  if not self.isBind then
    return
  end
  self.bind.txt_posIndex = tostring(self.bind.posIndex)
  self.bind.isOn_switchPos = self.bind.isChangePosMode == true
  self.bind.isOn_addPet = self.bind.roleType == L_Const.roleType.pet
end

function this:setFollow()
  local pointPos = L_FormationManager:getPlacePos(self.bind.posIndex, self.bind.roleType)
  local pointPosStandard = L_FormationManager:getPlacePos(3, L_Const.roleType.pet)
  pointPos.y = pointPosStandard.y + 0.5
  local screenPos = C_CameraManager.mainCamera:WorldToScreenPoint(pointPos)
  local v2 = C_Vector2(screenPos.x, screenPos.y)
  local btnRect = self.uiBinding.gameObject:GetComponent(typeof(C_RectTransform))
  local parent = btnRect.parent
  local _, uiPos = _screenPosToUI(parent, v2, C_CameraManager.uiCamera)
  L_Vector3.setAnchored(btnRect, uiPos)
end

return this
