local this = class("mapMiniAreaBlockNode", require("ui.manager.map.node.mapNode"))
local _typeTxt = typeof(C_LTextMeshProUGUI)
local _typeRect = typeof(C_RectTransform)
local PATH_MINIAREABLOCKNODE = "UI/Pages/Map/BigMap/miniAreaBlockNode.prefab"

function this:ctor(type)
  self.type = type
  self.id = nil
  self.name = nil
end

function this:setShow(isShow)
  self.isShow = isShow
  if self.go then
    self:disposeTween()
    local target = isShow and 1 or 0
    local getter1 = function()
      return self.canvasGroup.alpha
    end
    local setter1 = function(r)
      self.canvasGroup.alpha = r
    end
    self.tweenAlpha = DOTween.To(getter1, setter1, target, 0.15)
  end
end

function this:generate(parent, pool)
  self:_generate(parent, pool or L_ResPool)
  if parent then
    self.trans:Reset(parent)
  else
    L_Vector3.setScale(self.trans, L_Vector3.getTemp(1, 1, 1))
    L_Vector3.setLocalPos(self.trans, L_Vector3.getTemp())
  end
  self.go.name = self.id
  self.isShow = true
  if not string.isEmpty(self.name) then
    self.txtNode.text = self.name
  end
end

function this:_generate(parent, pool)
  local go = pool:syncGameObject(PATH_MINIAREABLOCKNODE)
  self.go = go
  self.trans = self.go:GetComponent(_typeRect)
  self.areaNameGo = self.go.transform:Find("areaName").gameObject
  self.txtNode = self.areaNameGo:GetComponent(_typeTxt)
  self.canvasGroup = self.go:GetComponent(typeof(C_CanvasGroup))
end

function this:refreshPosByMapData(mapData)
  this.super.refreshPosByMapData(self, mapData)
end

function this:refreshState(mapData)
  local percent = mapData:getPercent()
  local canShow = percent <= 1 and 0.33 < percent
  self:setShow(canShow)
end

function this:onDestroy()
  self:disposeTween()
  this.super.onDestroy(self)
end

function this:disposeTween()
  if self.tweenAlpha then
    self.tweenAlpha:Kill()
    self.tweenAlpha = nil
  end
end

return this
