local SSA, Auras = unpack(select(2,...))

-- Totem Mastery Notification
local WindfuryWeapon = CreateFrame('Frame','WindfuryWeapon',SSA.AuraBase,BackdropTemplateMixin and "BackdropTemplate")
WindfuryWeapon:SetPoint('CENTER',0,-220)
WindfuryWeapon:SetWidth(450)
WindfuryWeapon:SetHeight(100)
WindfuryWeapon:SetFrameStrata('BACKGROUND')
WindfuryWeapon:RegisterForDrag('LeftButton')
WindfuryWeapon:SetAlpha(0)
WindfuryWeapon:Show()

WindfuryWeapon.level = 10

WindfuryWeapon.header = WindfuryWeapon:CreateFontString(nil, 'MEDIUM', 'GameFontHighlightLarge')
WindfuryWeapon.header:SetFont([[Interface\AddOns\ShamanAuras2\Media\fonts\PT_Sans_Narrow.TTF]], 14,'OUTLINE')
WindfuryWeapon.header:SetPoint('TOPLEFT',WindfuryWeapon,"TOPLEFT",5,5)
WindfuryWeapon.header:SetTextColor(1,1,1,1)
WindfuryWeapon.header:SetText(GetSpellInfo(210643))
WindfuryWeapon.header:Hide()
				
WindfuryWeapon.texture = WindfuryWeapon:CreateTexture(nil,'LOW')
--WindfuryWeapon.texture:SetTexture([[Textures\SpellActivationOverlays\Echo_of_the_Elements]])
WindfuryWeapon.texture:SetTexture(603338)
WindfuryWeapon.texture:SetPoint('CENTER',WindfuryWeapon,'CENTER',0,10)
WindfuryWeapon.texture:SetWidth(WindfuryWeapon:GetHeight() * 2)
WindfuryWeapon.texture:SetHeight(WindfuryWeapon:GetWidth() * 0.6)
WindfuryWeapon.texture:SetRotation(rad(-90))
WindfuryWeapon.texture:SetAlpha(0.7)

-- Animation for Totem Mastery Notification Texture
WindfuryWeapon.Flash = WindfuryWeapon.texture:CreateAnimationGroup()
WindfuryWeapon.Flash:SetLooping('BOUNCE')

WindfuryWeapon.Flash.fadeIn = WindfuryWeapon.Flash:CreateAnimation('Alpha')
WindfuryWeapon.Flash.fadeIn:SetFromAlpha(1)
WindfuryWeapon.Flash.fadeIn:SetToAlpha(0.4)
WindfuryWeapon.Flash.fadeIn:SetDuration(0.4)

WindfuryWeapon.Flash.fadeOut = WindfuryWeapon.Flash:CreateAnimation('Alpha')
WindfuryWeapon.Flash.fadeOut:SetFromAlpha(0.4)
WindfuryWeapon.Flash.fadeOut:SetToAlpha(1)
WindfuryWeapon.Flash.fadeOut:SetDuration(0.4)
WindfuryWeapon.Flash.fadeOut:SetEndDelay(0)

WindfuryWeapon:SetScript('OnUpdate',function(self)
	if (not Auras.db.char.isFirstEverLoad and UnitEffectiveLevel("player") > self.level) then
		if (Auras:CharacterCheck(self,2)) then
			local spec = GetSpecialization()

			local remaining = 0
			local isRefresh = false
			--local buff = UnitBuff('player',Auras:GetSpellName(202192))
			--local buff = Auras:RetrieveAuraInfo("player", 202192)
			local _,mainExpires,_,mainEnchantID,_,offExpires,_,offEnchantID = GetWeaponEnchantInfo()

			local db = Auras.db.char
		
			self:SetPoint(db.elements[spec].frames[self:GetName()].point,SSA[db.elements[spec].frames[self:GetName()].relativeTo],db.elements[spec].frames[self:GetName()].relativePoint,db.elements[spec].frames[self:GetName()].x,db.elements[spec].frames[self:GetName()].y)
			Auras:ToggleFrameMove(self,Auras.db.char.settings.move.isMoving)
			Auras:ToggleAuraVisibility(self,true,'showhide')

			if (mainEnchantID == 5401) then
				remaining = (mainExpires or 0) - GetTime()
			elseif (offEnchantID == 5401) then
				remaining = (offExpires or 0) - GetTime()
			end

			if ((remaining or 0) <= db.settings[spec].windfuryWeapon) then
				isRefresh = true
			end

			if (((isRefresh or ((mainEnchantID or 0) ~= 5401 and (offEnchantID or 0) ~= 5401)) and db.elements[spec].frames.WindfuryWeapon.isEnabled and SSA.isFlametongue and SSA.isLightningShield) or db.settings.move.isMoving) then
				self:SetAlpha(1)
				
				if (not self.Flash:IsPlaying()) then
					self.Flash:Play()
				end
				if (UnitAffectingCombat('player')) then
					self.Flash.fadeOut:SetToAlpha(0.6)
					self.Flash.fadeIn:SetFromAlpha(1)
				else
					self.Flash.fadeOut:SetToAlpha(0.3)
					self.Flash.fadeIn:SetFromAlpha(0.6)
				end
			else
				self:SetAlpha(0)
				
				if (self.Flash:IsPlaying()) then
					self.Flash:Stop()
				end
			end
		else
			self:SetAlpha(0)
		end
		
		--Auras:ToggleFrameMove(self,db.elements[1].isMoving)
	--else
		--Auras:ToggleAuraVisibility(self,false,'showhide')
	--end
	end
end)

WindfuryWeapon:SetScript('OnMouseDown',function(self,button)
	if (Auras.db.char.settings.move.isMoving) then
		Auras:MoveOnMouseDown(self,button)
	end
end)

WindfuryWeapon:SetScript('OnMouseUp',function(self,button)
	if (Auras.db.char.settings.move.isMoving) then
		local spec = GetSpecialization()

		Auras:MoveOnMouseUp(self,button)
		Auras:UpdateLayout(self,Auras.db.char.elements[spec].frames[self:GetName()])
	end
end)

_G["SSA_WindfuryWeapon"] = WindfuryWeapon