local module = class("modulePetFeather", G_UIModuleBase)
local petInfoTpl = L_GameTpl:getPetTpl()
local battleInfoTpl = L_GameTpl:getBattleInfoTpl()
local petFeatureTpl = L_GameTpl:getPetFeatureTpl()

function module:ctor(...)
  module.super.ctor(self, ...)
end

function module.bind()
  return {
    tagList_feather = {
      moduleName = "pages/pet/new/cellNewTagItem"
    },
    active_tagTip_feather = false,
    list_tagTip_feather = {
      moduleName = "pages/pet/new/cellNewTagTipItem"
    },
    size_tipBoard_feather = C_Vector2(750, 853)
  }
end

function module.methods()
  return {
    onClick_tagTip_feather = function(self)
      if #self.bind.list_tagTip_feather < 1 then
        return
      end
      self.bind.active_tagTip_feather = true
      self:emit("onCLickTagTipFeather")
      Unity.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(self.bindComponents.tagTipNode_feather)
      self.bind.size_tipBoard_feather = C_Vector2(750, math.min(self.bindComponents.tagTipNode_feather.sizeDelta.y + 34, 700))
    end,
    onClick_closeTips = function(self)
      self.bind.active_tagTip_feather = false
    end
  }
end

function module:closeTip()
  self.bind.active_tagTip_feather = false
end

function module:created(...)
  module.super.created(self, ...)
  self.uiCamera = C_CameraManager.uiCamera
  self.screenPosToUI = Unity.RectTransformUtility.ScreenPointToLocalPointInRectangle
end

function module:open()
end

function module:close()
end

function module:setGuid(petGuid)
  local pet = L_PetStore:getPetItem(petGuid)
  self.bind.tagList_feather:clear()
  self.bind.list_tagTip_feather:clear()
  local tagData = {}
  local tagTipData = {}
  local kiboDuelFeatureSkill = L_PetManager:getKiboFPropertySkillList(pet.id)
  local featureList = L_PetStore:getPetFeatureSkill(pet)
  table.fill(kiboDuelFeatureSkill, featureList)
  for i, v in ipairs(kiboDuelFeatureSkill) do
    table.insert(tagData, {
      type = i % 3 == 0 and 3 or i % 3,
      label = string.format("%s", v.skillName)
    })
    table.insert(tagTipData, {
      type = i % 3 == 0 and 3 or i % 3,
      label = string.format("%s", v.skillName),
      txt_desc = string.isEmpty(v.describe) and "\230\178\161\233\133\141\230\143\143\232\191\176 \231\173\150\229\136\146\229\191\171\229\142\187\233\133\141!" or v.describe
    })
  end
  self.bind.tagList_feather:insert_array(tagData)
  self.bind.list_tagTip_feather:insert_array(tagTipData)
end

function module:setConfigId(petConfigId)
  self.configId = petConfigId
  self.bind.tagList_feather:clear()
  self.bind.list_tagTip_feather:clear()
  local tagData = {}
  local tagTipData = {}
  local kiboDuelFeatureSkill = L_PetManager:getKiboFPropertySkillList(petConfigId)
  local randomfeatureList, fixedFeatureList = L_PetManager:getPetConfigFeatureSkill(petConfigId)
  table.fill(kiboDuelFeatureSkill, fixedFeatureList)
  for i, v in ipairs(kiboDuelFeatureSkill) do
    table.insert(tagData, {
      type = i % 3 == 0 and 3 or i % 3,
      label = string.format("%s", v.skillName)
    })
    table.insert(tagTipData, {
      type = i % 3 == 0 and 3 or i % 3,
      label = string.format("%s", v.skillName),
      txt_desc = string.isEmpty(v.describe) and "\230\178\161\233\133\141\230\143\143\232\191\176 \231\173\150\229\136\146\229\191\171\229\142\187\233\133\141!" or v.describe
    })
  end
  self.bind.tagList_feather:insert_array(tagData)
  self.bind.list_tagTip_feather:insert_array(tagTipData)
end

return module
