local item = class("cellGroupTask", G_UIModuleBase)

function item.bind()
  return {
    tabId = 0,
    txtNameOn = "",
    txtNameOff = "",
    txtMapOn = "",
    txtMapOff = "",
    activeTackingOn = false,
    activeTackingOff = false,
    activeNoTackOn = true,
    activeNoTackOff = true,
    activeRed = false,
    anchoredPosNameOn = nil,
    anchoredPosNameOff = nil,
    activeLimitIcon = false,
    activeTimeLimit = false,
    txtTimeLimit = "",
    showLimit = false,
    txtLimit = ""
  }
end

function item.methods()
  return {}
end

function item:open()
  self.isOpen = true
  if self.bind.endTime then
    self.bind.activeTimeLimit = true
    self:refreshTimeLimit()
    self.timer = Timer.repeated(1, self.refreshTimeLimit, self)
    local colorStr = self.bind.activeTackingOn and "#FF7E6D" or "#BCF6DE"
    local _, color = C_ColorUtility.TryParseHtmlString(colorStr)
    self.bindComponents.groupTimeLimit.color = color
  end
  self:refreshTrace(self.bind.tacking)
  self:refreshSelected()
end

function item:close()
  self.isOpen = false
  if self.timer then
    Timer.remove(self.timer)
    self.timer = nil
  end
end

function item:refreshTimeLimit()
  self.bind.txtTimeLimit = L_TimeUtil.getLeftTimeString2(self.bind.endTime)
end

function item:refreshSelected()
  if not self.isOpen then
    return
  end
  if self.bind.endTime then
    local colorStr = self.bindComponents.tabItem.isOn and "#FF7E6D" or "#BCF6DE"
    local _, color = C_ColorUtility.TryParseHtmlString(colorStr)
    self.bindComponents.groupTimeLimit.color = color
  end
  if self.bindComponents.tabItem.isOn then
    self.bind.activeRed = false
  end
end

function item:refreshTrace(tacking)
  if not self.bind.activeLimitIcon then
    self.bind.tacking = tacking
    self.bind.activeTackingOn = tacking
    self.bind.activeTackingOff = tacking
    self.bind.activeNoTackOn = not tacking
    self.bind.activeNoTackOff = not tacking
  end
end

return item
