local this = class("moduleCharacterStandee", G_UIModuleBase)
local _playerDressTpl = L_GameTpl:getPlayercardDressTpl()

function this.bind()
  return {
    img_displayBg = "",
    img_displayCharacter = "",
    img_displayPet = "",
    img_displayBase = "",
    isActive_Character = true,
    isActive_Pet = true,
    isActive_Base = true,
    isActive_Bg = true,
    isActive_outLine = false
  }
end

function this.methods()
  return {}
end

function this:showByPlayerId()
end

function this:setStandeeByBaseInfo(baseInfo)
  self.baseInfo = baseInfo
  local stand_plates = baseInfo.stand_plates
  if stand_plates == nil or stand_plates.role == nil then
    return
  end
  self:setPet({
    id = stand_plates.pet_accessory
  })
  self:setBase({
    id = stand_plates.baseboard
  })
  self:setBg({
    id = stand_plates.backboard
  })
  self:setCharacter({
    id = stand_plates.role.config,
    url = stand_plates.role.url
  })
end

function this:setCharacter(data)
  local id = data.id
  self.url = data.url
  local tpl = _playerDressTpl:getTplById(id)
  if tpl == nil then
    self.bind.isActive_Character = false
    self.bind.isActive_outLine = false
    return false
  end
  local isCustom = tpl.customize == 1
  if isCustom then
    self.bind.isActive_Character = false
    if not string.isEmpty(data.url) then
      local isSelf = L_PlayerStore:getPlayerBaseInfo().id == self.baseInfo.id
      L_PlayerDisplayStore:getHeroStandeeCapture(data.url, isSelf, function(tex, url)
        if url == self.url then
          self:setOutlineImg(tex)
        end
      end)
    else
    end
  else
    self.bind.isActive_Character = true
    if tpl.defaultComponent == 1 then
      self.bind.isActive_Character = false
      L_PhotoManager:loadHeadTex(L_FriendStore:getPlayerAvatars(self.baseInfo, L_Const.avatarTextureIndex.body), function(tex)
        self:setOutlineImg(tex)
      end)
    else
      self.bind.isActive_outLine = false
      self.bind.img_displayCharacter = _playerDressTpl:getPic(tpl)
      local rect = self.bindComponents.img_displayCharacter.transform
      rect.sizeDelta = C_Vector2(500, 690)
    end
  end
  if data.isGray == true then
    self.bindComponents.img_displayCharacter.color = C_Color.gray
  else
    self.bindComponents.img_displayCharacter.color = C_Color.white
  end
end

function this:setOutlineImg(tex)
  if self.bindComponents.heroimg == nil or tex == nil then
    return
  end
  self.bind.isActive_outLine = true
  self.bindComponents.heroimg.texture = tex
  self.bindComponents.outline.texture = tex
  self.bindComponents.shadow.texture = tex
  local SDFGenorateToShader = self.bindComponents.SDFGenorateToShader
  SDFGenorateToShader.inputTexture = tex
  local rt = SDFGenorateToShader:GenerateSDFWithJFA()
  self.sdf = rt
  self.bindComponents.outline.material = C_UnityObject.Instantiate(self.bindComponents.outline.material)
  self.bindComponents.shadow.material = C_UnityObject.Instantiate(self.bindComponents.shadow.material)
  self.bindComponents.outline.material:SetTexture("_InputTexture", rt)
  self.bindComponents.shadow.material:SetTexture("_InputTexture", rt)
  self.bindComponents.outline:SetNativeSize()
  self.bindComponents.heroimg:SetNativeSize()
  self.bindComponents.shadow:SetNativeSize()
end

function this:setPet(data)
  local tpl = _playerDressTpl:getTplById(data.id)
  if tpl == nil then
    return
  end
  self.bind.img_displayPet = _playerDressTpl:getPic(tpl)
  self.bindComponents.img_displayPet:SetNativeSize()
  if data.isGray == true then
    self.bindComponents.img_displayPet.color = C_Color.gray
  else
    self.bindComponents.img_displayPet.color = C_Color.white
  end
end

function this:setBase(data)
  local tpl = _playerDressTpl:getTplById(data.id)
  if tpl == nil then
    return
  end
  self.bind.img_displayBase = _playerDressTpl:getPic(tpl)
  self.bindComponents.img_displayBase:SetNativeSize()
  if data.isGray == true then
    self.bindComponents.img_displayBase.color = C_Color.gray
  else
    self.bindComponents.img_displayBase.color = C_Color.white
  end
end

function this:setBg(data)
  local tpl = _playerDressTpl:getTplById(data.id)
  if tpl == nil then
    return
  end
  self.bind.img_displayBg = _playerDressTpl:getPic(tpl)
  self.bindComponents.img_displayBg:SetNativeSize()
  if data.isGray == true then
    self.bindComponents.img_displayBg.color = C_Color.gray
  else
    self.bindComponents.img_displayBg.color = C_Color.white
  end
end

function this:close()
end

return this
