local VERSION = tonumber(("$Revision: 31377 $"):match("%d+"))

local QuestsFu = QuestsFu
local QuestsFu_Sound = QuestsFu:NewModule("Sound", "AceEvent-2.0", "AceConsole-2.0")
if QuestsFu.revision < VERSION then
	QuestsFu.version = "r" .. VERSION
	QuestsFu.revision = VERSION
	QuestsFu.date = ("$Date: 2007-03-30 07:58:47 -0400 (Fri, 30 Mar 2007) $"):match("%d%d%d%d%-%d%d%-%d%d")
end

local L = AceLibrary("AceLocale-2.2"):new("QuestsFu_Sound")
L:RegisterTranslations("enUS", function() return {
	["Sound"] = true,
	["Play sounds in response to quest events"] = true,
	["Sound on complete"] = true,
	["Play a sound when all a quests' objectives are complete"] = true,
} end)

L:RegisterTranslations("deDE", function() return {
	["Sound"] = "Sound",
	["Play sounds in response to quest events"] = "Sounds bei Quest Ereignissen abspielen.",
	["Sound on complete"] = "Sound bei Abschluss",
	["Play a sound when all a quests' objectives are complete"] = "Spiele einen Sound wenn von einer Quest alle Missionsziele fertiggestellt sind.",
} end)

L:RegisterTranslations("koKR", function() return {
	["Sound"] = "효과음",
	["Play sounds in response to quest events"] = "퀘스트 이벤트시 효과음을 알림니다.",
	["Sound on complete"] = "사운드 효과",
	["Play a sound when all a quests' objectives are complete"] = "퀘스트 진행상황이 완료되었을 경우 사운드로 퀘스트가 완료되었음을 알립니다.",
} end)

L:RegisterTranslations("zhTW", function() return {
	["Sound"] = "音效",
	["Play sounds in response to quest events"] = "依據任務事件播放音效",
	["Sound on complete"] = "完成音效",
	["Play a sound when all a quests' objectives are complete"] = "任務完成之後就播放音效",
} end)

function QuestsFu_Sound:OnInitialize()
	self.db = QuestsFu:AcquireDBNamespace("Sound")
	QuestsFu:RegisterDefaults("Sound", "profile", {
		--["enabled"] = true,
		["complete"] = true,
	})
	QuestsFu.options.args.Sound = {
		name = L["Sound"],
		desc = L["Play sounds in response to quest events"],
		type = "group",
		args = {
			complete = {
				type = 'toggle', name = L["Sound on complete"],
				desc = L["Play a sound when all a quests' objectives are complete"],
				get = function() return self.db.profile.complete end,
				set = function(t) self.db.profile.complete = t end,
			},
			toggle = {
				name = AceLibrary("AceLocale-2.2"):new("QuestsFu")["Enabled"],
				desc = AceLibrary("AceLocale-2.2"):new("QuestsFu")["Suspend/resume this module."],
				type = 'toggle',
				order = -1,
				get = function() return QuestsFu:IsModuleActive(self) end,
				set = function() QuestsFu:ToggleModuleActive(self) end
			},
		},
	}
end

function QuestsFu_Sound:OnEnable()
	self:RegisterEvent("Quixote_Quest_Complete")
end

function QuestsFu_Sound:Quixote_Quest_Complete(name, id)
	if self.db.profile.complete then
		PlaySoundFile("Sound\\Creature\\Peon\\PeonBuildingComplete1.wav")
	end
end