local this = class("cellChatMessage", G_UIModuleBase)

function this:ctor(...)
  this.super.ctor(self, ...)
  self.data = {photoEntity = nil}
end

function this.bind()
  return {txt_name = "", txt_message = ""}
end

function this.methods()
  return {
    onClick_head = function(self)
      L_FriendManager:viewPlayerCard(self.bind.playerUid)
    end
  }
end

function this:refresh()
  local textWidth = self.bindComponents.txt_message.preferredWidth + 40
  local line = math.ceil(textWidth / 495)
  local width = 535
  local height = 68
  if line <= 1 then
    width = textWidth
  else
    height = line * 30 + 38
  end
  self.bindComponents.rect_messageBox.sizeDelta = C_Vector2(width, height)
  if not string.isEmpty(self.bind.url_head) then
    if self.data.photoEntity == nil then
      self.data.photoEntity = L_PhotoManager:bindPhotoEntity(self.bindComponents.img_head.gameObject, self.bind.url_head)
    else
      self.data.photoEntity:bindGameObject(self.bindComponents.img_head.gameObject)
    end
  end
  if self.bindComponents.img_shield then
    self.bindComponents.img_shield.gameObject:ActiveTrans(L_ChatStore:getIsShieldChat(self.bind.playerUid))
  end
  if self.bindComponents.img_friend then
    self.bindComponents.img_friend.gameObject:ActiveTrans(L_FriendStore:getIsFriend(self.bind.playerUid) and L_ChatStore:getIsMessageFromMeeting(self.bind.serverData))
  end
end

function this:playInitFX()
  if self.bindComponents and self.bindComponents.ani_cellMessage then
    self.bindComponents.ani_cellMessage:Play()
  end
end

return this
