local this = class("cellAccessorySubAttStrength", G_UIModuleBase)

function this.bind()
  return {
    isOn_lockDesc = false,
    txt_desc_lock = nil,
    txt_desc_unlock = nil,
    isOn_lockImg = false,
    color_lock = C_Color(0.06666666666666667, 0.10196078431372549, 0.13333333333333333, 0.2),
    active_noneBg = false,
    active_whiteBg = false,
    active_blueBg = false,
    active_blackBg = false,
    anchorsMax_blueBg = C_Vector2(1, 1)
  }
end

function this:refresh()
  self:initCell()
end

function this:initCell()
  if not self.isBind then
    return
  end
  self:clearTimer()
  if self.bind.index == self.bind.newUnlockIndex then
    self.timer1 = Timer.once(0.1, function()
      self.bindComponents.anim:Play("anim_AStrength_unlock")
      L_AudioUtil.playSound("Play_SFX_System_UI_Equipment_Unlock")
      self.timer2 = Timer.once(1, function()
        self.bind.active_blueBg = false
      end, self)
      self.timer3 = Timer.once(0.165, function()
        self.bind.txt_desc_unlock = self.bind.desc
        self.bind.txt_desc_lock = self.bind.desc
      end, self)
    end, self)
    self.bind.isOn_lockDesc = not self.bind.lock or self.bind.showHighLight
    self.bind.isOn_lockImg = self.bind.lock
    local bgTabGroupId = self.bind.showBg and L_AccessoryConst.StrengthSubAttBgTabId.White or L_AccessoryConst.StrengthSubAttBgTabId.None
    if self.bind.lock then
      bgTabGroupId = L_AccessoryConst.StrengthSubAttBgTabId.Grey
    end
    if self.bind.showHighLight then
      bgTabGroupId = L_AccessoryConst.StrengthSubAttBgTabId.Blue
    end
    self.bind.active_noneBg = bgTabGroupId == L_AccessoryConst.StrengthSubAttBgTabId.None
    self.bind.active_whiteBg = bgTabGroupId == L_AccessoryConst.StrengthSubAttBgTabId.White
    self.bind.active_blackBg = bgTabGroupId == L_AccessoryConst.StrengthSubAttBgTabId.Grey
  elseif self.bind.index == self.bind.unlockNextIndex then
    self.timer1 = Timer.once(0.785, function()
      self.bind.anchorsMax_blueBg = C_Vector2(0, 1)
      self.bind.active_blueBg = true
      self.bindComponents.anim:Play("anim_AStrength_unlock_next")
      self.timer2 = Timer.once(0.667, function()
        self.bind.active_blackBg = false
      end, self)
    end, self)
    self.bind.txt_desc_lock = self.bind.desc
    self.bind.txt_desc_unlock = self.bind.desc
    self.bind.isOn_lockDesc = not self.bind.lock or self.bind.showHighLight
    self.bind.isOn_lockImg = self.bind.lock
    local bgTabGroupId = self.bind.showBg and L_AccessoryConst.StrengthSubAttBgTabId.White or L_AccessoryConst.StrengthSubAttBgTabId.None
    if self.bind.lock then
      bgTabGroupId = L_AccessoryConst.StrengthSubAttBgTabId.Grey
    end
    if self.bind.showHighLight then
      bgTabGroupId = L_AccessoryConst.StrengthSubAttBgTabId.Blue
    end
    self.bind.active_noneBg = bgTabGroupId == L_AccessoryConst.StrengthSubAttBgTabId.None
    self.bind.active_whiteBg = bgTabGroupId == L_AccessoryConst.StrengthSubAttBgTabId.White
    if self.bind.showHighLight then
      self.bindComponents.animLock:Play("anim_AStrength_unlock_lockloop")
    end
  else
    self.bind.txt_desc_lock = self.bind.desc
    self.bind.txt_desc_unlock = self.bind.desc
    self.bind.isOn_lockDesc = not self.bind.lock or self.bind.showHighLight
    self.bind.isOn_lockImg = self.bind.lock
    local bgTabGroupId = self.bind.showBg and L_AccessoryConst.StrengthSubAttBgTabId.White or L_AccessoryConst.StrengthSubAttBgTabId.None
    if self.bind.lock then
      bgTabGroupId = L_AccessoryConst.StrengthSubAttBgTabId.Grey
    end
    if self.bind.showHighLight then
      bgTabGroupId = L_AccessoryConst.StrengthSubAttBgTabId.Blue
    end
    self.bind.active_noneBg = bgTabGroupId == L_AccessoryConst.StrengthSubAttBgTabId.None
    self.bind.active_whiteBg = bgTabGroupId == L_AccessoryConst.StrengthSubAttBgTabId.White
    self.bind.active_blueBg = bgTabGroupId == L_AccessoryConst.StrengthSubAttBgTabId.Blue
    self.bind.active_blackBg = bgTabGroupId == L_AccessoryConst.StrengthSubAttBgTabId.Grey
    if self.bind.showHighLight then
      self.bindComponents.animLock:Play("anim_AStrength_unlock_lockloop")
    end
  end
end

function this:clearTimer()
  if self.timer1 then
    Timer.remove(self.timer1)
    self.timer1 = nil
  end
  if self.timer2 then
    Timer.remove(self.timer2)
    self.timer2 = nil
  end
  if self.timer3 then
    Timer.remove(self.timer3)
    self.timer3 = nil
  end
end

function this:close()
  self:clearTimer()
end

return this
