local item = class("cellTaskDetail", G_UIModuleBase)

function item.bind()
  return {
    activeDetails = true,
    taskDetails = "",
    taskTrace = "",
    color_taskTraceIcon = nil,
    traceLimit = "",
    taskBtnObj = false,
    activeTraceLimit = false,
    alpha_root = 1
  }
end

function item.methods()
  return {
    on_clickOpenBigMap = function(self)
      self:onClick()
    end
  }
end

function item:open()
  local height = 0
  Unity.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(self.bindComponents.transContent)
  if self.bind.taskBtnObj then
    height = -self.bindComponents.transTraceBtn.offsetMin.y
  elseif self.bind.activeTraceLimit then
    height = -self.bindComponents.transTraceLimit.offsetMin.y
  else
    height = -self.bindComponents.transTextTarget.offsetMin.y
  end
  local size = self.gameObject.transform.sizeDelta
  size.y = height
  self.gameObject.transform.sizeDelta = size
  self.bind.alpha_root = self.bind.isSecondary and 0.7 or 1
  if self.bind.taskBtnObj then
    local colorStr = self.bind.isSecondary and "#BCF6DE" or "#FFD013"
    local _, color = C_ColorUtility.TryParseHtmlString(colorStr)
    self.bind.color_taskTraceIcon = color
    self.bind.taskTrace = L_GameUtil.fillColor(self.bind.taskTrace, colorStr)
  end
end

function item:showCutKey()
  if self.cutKey then
    return
  end
  self.cutKey = true
  L_ShortCutManager:addListener(L_ShortCutConst.event.TaskToMap, self.onClick, self)
  L_ShortCutManager:addShortKeyFlag(self, "V", L_Const.AnchorType.Right, self.bindComponents.transTrace, L_Vector3.new(10, 0, 0), 0.8)
end

function item:hideCutKey()
  if not self.cutKey then
    return
  end
  self.cutKey = false
  L_ShortCutManager:removeListener(L_ShortCutConst.event.TaskToMap, self.onClick, self)
  L_ShortCutManager:clearShortKeyFlag(self)
end

function item:onClick()
  if self.bind.clickCB then
    self.bind.clickCB()
  end
end

function item:close()
  self:hideCutKey()
end

function item:playAnim(name)
  self.bindComponents.animation:Stop()
  self.bindComponents.animation:Play(name)
end

return item
