local dewdrop = DewdropLib:GetInstance('1.0')
local tablet = TabletLib:GetInstance('1.0')
local metro = Metrognome:GetInstance('1')

ExampleFu = FuBarPlugin:GetInstance("1.2"):new({
	name          = ExampleFuLocals.NAME,
	description   = ExampleFuLocals.DESCRIPTION,
	version       = "0.1.0",
	releaseDate   = "03-29-2006",
	aceCompatible = 103,
	author        = "Mr. Plugin Writer",
	email         = "plugin@writer.com",
	website       = "http://plugin--writer.wowinterface.com/",
	category      = "others", -- Set this to the appropriate category.
	db            = AceDatabase:new("ExampleFuDB"),
	defaults      = {
		value = false,
	},
	cmd           = AceChatCmd:new(ExampleFuLocals.COMMANDS, ExampleFuLocals.CMD_OPTIONS),
	loc           = ExampleFuLocals,
	hasIcon       = false,
	showOnRight   = false,
})

function ExampleFu:IsValue()
	-- self.data is a database provided for you (inside ExampleFuDB) that is specific to the current profile.
	return self.data.value
end

function ExampleFu:ToggleValue(loud)
	self.data.value = not self.data.value
	if loud then -- loud will be set to a string if called from the command line, thus being non-false.
		self.cmd:status(self.loc.ARGUMENT_VALUE, self.data.value and 1 or 0, FuBarLocals.MAP_ONOFF)
	end
	self:Update()
	return self.data.value
end

function ExampleFu:Initialize()
	-- put something that would be run only once, at the start
	-- you can check if self.data.version is a previous version here, and if you do provide adequate steps for backwards-compatibiliy.
end

function ExampleFu:Enable()
	-- put something that would be run every time this is enabled. Happens at the very start as well, after Initialize.
	
	self:RegisterEvent("UNIT_TARGET_CHANGED")
	
	-- repetitive timer
	metro:Register(self.name, self.OnUpdate, 1.0, self)
	metro:Start(self.name)
end

function ExampleFu:Disable()
	-- you do not need to unregister the event here, all events/hooks are unregistered on disable implicitly.
	
	-- you do need to unregister your metrognome timer.
	metro:Unregister(self.name)
end

function ExampleFu:Report()
	-- this is run when the user types /bpex report
	self.cmd:report({
		{text=self.loc.ARGUMENT_VALUE, val=(self:IsValue() and 1 or 0), map=FuBarLocals.MAP_ONOFF},
	})
end

function ExampleFu:MenuSettings(level, value)
	-- this is run at the top of the dropdown menu, it is where you should allow your users to configure the plugin to their liking.
	dewdrop:AddLine(
		'text', self.loc.MENU_CHANGE_VALUE,
		'arg1', self,
		'func', "ToggleValue", -- you can also have func be an actual function.
		'checked', self:IsValue()
	)
end

function ExampleFu:UNIT_TARGET_CHANGED()
	-- do something here.
	-- this is called every time UNIT_TARGET_CHANGED is fired.
end

function ExampleFu:OnUpdate(t)
	-- this is run once every 1.0 seconds, as specified in the metrognome registry.
	self:Update()
end

function ExampleFu:UpdateData()
	-- calculate data you would use in both UpdateText() and UpdateTooltip() here.
	-- even if you only use one, it is typically better structure to calculate your data here anyway.
	self.textValue = 500
end

function ExampleFu:UpdateText()
	self:SetText(FuBarUtils.White(self.textValue))
end

function ExampleFu:UpdateTooltip()
	tablet:AddCategory(
		'text', "Alpha",
		'columns', 2,
		'child_textR', 1,
		'child_textG', 1,
		'child_textB', 0,
		'child_textR2', 1,
		'child_textG2', 1,
		'child_textB2', 1,
		'children', function()
			tablet:AddLine(
				'text', "Apple",
				'text2', "Banana"
			)
			
			tablet:AddLine(
				'text', "Cookie",
				'text2', "Monster"
			)
		end
	)
	
	tablet:AddCategory(
		'text', "Bravo",
		'columns', 2,
		'child_textR', 1,
		'child_textG', 1,
		'child_textB', 0,
		'child_textR2', 1,
		'child_textG2', 1,
		'child_textB2', 1,
		'children', function()
			tablet:AddLine(
				'text', "Dung",
				'text2', "Beetle"
			)
			
			tablet:AddLine(
				'text', "Elephant",
				'text2', "Tamer"
			)
		end
	)
	
	
	tablet:SetHint("Click to do something")
	-- as a rule, if you have an OnClick or OnDoubleClick or OnMouseUp or OnMouseDown, you should set a hint.
end

function ExampleFu:OnClick()
	-- do something
end

ExampleFu:RegisterForLoad()