local this = class("mapKiboHabitatNode", require("ui.manager.map.node.mapNode"))
local _typeImg = typeof(C_LImage)
local _typeRect = typeof(C_RectTransform)
local PATH_AREABLOCKNODE = "UI/Pages/Map/BigMap/cellKiboHabitatNode.prefab"

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)
  local go = pool:syncGameObject(PATH_AREABLOCKNODE)
  self.go = go
  self.trans = self.go:GetComponent(_typeRect)
  self.kiboGo = self.go.transform:Find("nodeIcon").gameObject
  self.img = self.kiboGo:GetComponent(_typeImg)
  self.img_bg = self.go.transform:Find("nodeIconBg").gameObject:GetComponent(_typeImg)
  self.canvasGroup = self.go:GetComponent(typeof(C_CanvasGroup))
  self.scope = self.go.transform:Find("scope").gameObject:GetComponent(_typeRect)
  if not string.isEmpty(self.icon) then
    self.img:LoadSprite(self.icon)
  end
end

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

function this:refreshState(mapData)
  local canShow = true
  self:setShow(canShow)
end

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

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

function this:refreshScope(value, ratio)
  local size = 200 + 200 * ratio * math.clamp(value, 0, 1)
  self.scope.sizeDelta = C_Vector2(size, size)
end

return this
