local this = class("cellChatEmotion", G_UIModuleBase)
local _emojiTpl = L_GameTpl:getChatEmojiTpl()

function this:ctor(...)
  this.super.ctor(self, ...)
  self.data = {
    photoEntity = nil,
    curFrameIndex = 1,
    maxFrame = 1,
    isAni = false
  }
end

function this.bind()
  return {
    txt_name = "",
    img_emotion = "",
    frameCountPerRow = 0,
    frameCountPerCol = 0,
    frameCount = 0,
    frameAnimParamsComplete = false,
    frameAniFps = 8
  }
end

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

function this:refresh()
  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
  local tpl = _emojiTpl:getTplById(tonumber(L_ChatStore:getMessageMsg(self.bind.serverData)))
  self.bind.img_emotion = _emojiTpl:getIcon(tpl)
  self.bind.frameCount = _emojiTpl:getMaxFrame(tpl)
  self.bind.frameCountPerRow = _emojiTpl:getFramePerRow(tpl)
  self.bind.frameCountPerCol = _emojiTpl:getFramePerCol(tpl)
  self.bind.frameAnimParamsComplete = true
end

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

return this
