--bgab_versionUpdate; a flag to tell 

local function AddShapeshiftScript()
	--make the first actionbar switch when changing stances/forms/stealthing
	local _, class = UnitClass("player")
	if class == "DRUID" or class == "WARRIOR" or class == "ROGUE" and not BCustomScript.GetScript(1, "UPDATE_BONUS_ACTIONBAR") then
		BCustomScript.Save(1, "UPDATE_BONUS_ACTIONBAR", 
			[[if GetBonusBarOffset() ~= 0 then
				BActionBar.SetStanceOffset(bar.id, 5 + GetBonusBarOffset())
			else
				BActionBar.SetStanceOffset(bar.id, 0)
			end]]
		)
	end
end

local function UpdateVersion(currentVersion)
	AddShapeshiftScript();
	BActionSets.g.rightClickSelfCast = 1;
	BActionSets.version = currentVersion;
end

local function LoadVariables()
	local currentVersion = GetAddOnMetadata("Bongos_ActionBar", "Version")

	if not BActionSets or not BActionSets.g.version then
		BMsg("Loading Defaults");
		local defaults = BProfile.GetDefaultValue("BActionSets.g");
		BActionSets = {
			g = defaults or {
				version = currentVersion,
				buttonLocked = 1,
				tooltips = 1,
				altCast = 1,
				quickMove = 2,
				colorOutOfRange = 1,
				rangeColor = {r = 1, g = 0.5, b = 0.5},
				numActionBars = 10,
				rightClickSelfCast = 1,
			},
		};
		
		AddShapeshiftScript()
	elseif BActionSets.version ~= currentVersion then
		UpdateVersion(currentVersion);
	end
end

BScript.AddEventAction("ADDON_LOADED", function(thisAction)
	if arg1 == "Bongos_ActionBar" then
		BScript.RemoveEventAction("ADDON_LOADED", thisAction);
		LoadVariables();
		BProfile.RegisterForSave("BActionSets.g", LoadVariables);
	end
end);