local function OnEvent(self, event, addOnName)
	if addOnName == "wheredoigetit" then 
		WDIGI_APP_SETTINGS = WDIGI_APP_SETTINGS or {} 
		WDIGI_APP_SETTINGS.WDIGI_ShowItemID_Toggle = WDIGI_APP_SETTINGS.WDIGI_ShowItemID_Toggle or false
		WDIGI_APP_SETTINGS.WDIGI_ALTKey_Toggle = WDIGI_APP_SETTINGS.WDIGIC_ALTKey_Toggle or false
		WDIGI_APP_SETTINGS.WDIGI_LocationListLimitDroppedBy_Slider = WDIGI_APP_SETTINGS.WDIGIC_LocationListLimitDroppedBy_Slider or 5
		WDIGI_APP_SETTINGS.WDIGI_LocationListLimitSoldBy_Slider = WDIGI_APP_SETTINGS.WDIGIC_LocationListLimitSoldBy_Slider  or 5
	end
end

local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", OnEvent)

local category = Settings.RegisterVerticalLayoutCategory("Where Do I Get It?")

local function OnSettingChanged(setting, value)
	-- This callback will be invoked whenever a setting is modified, 
	-- updating SavedVariables
	WDIGI_APP_SETTINGS[setting:GetVariable()] = value
end

do 
	-- RegisterProxySetting will run the GetValue and SetValue
	-- callbacks whenever access to the setting is required.
    local name = "Show Item ID"
    local variable = "WDIGI_ShowItemID_Toggle"
    local defaultValue = false

	local function GetValue()
		return WDIGI_APP_SETTINGS.WDIGI_ShowItemID_Toggle or defaultValue
	end

	local function SetValue(value)
		WDIGI_APP_SETTINGS.WDIGI_ShowItemID_Toggle = value
	end
	
	local setting = Settings.RegisterProxySetting(category, variable, type(defaultValue), name, defaultValue, GetValue, SetValue)
	setting:SetValueChangedCallback(OnSettingChanged)

    local tooltip = "Show Item ID in Tooltip"
	Settings.CreateCheckbox(category, setting, tooltip)
end

do 
	-- RegisterProxySetting will run the GetValue and SetValue
	-- callbacks whenever access to the setting is required.
    local name = "Enable ALT Hotkey"
    local variable = "WDIGIC_ALTKey_Toggle"
    local defaultValue = false

	local function GetValue()
		return WDIGI_APP_SETTINGS.WDIGI_ALTKey_Toggle or defaultValue
	end

	local function SetValue(value)
		WDIGI_APP_SETTINGS.WDIGI_ALTKey_Toggle = value
	end
	
	local setting = Settings.RegisterProxySetting(category, variable, type(defaultValue), name, defaultValue, GetValue, SetValue)
	setting:SetValueChangedCallback(OnSettingChanged)

    local tooltip = "Show locations in Tooltip only if either ALT key is pressed"
	Settings.CreateCheckbox(category, setting, tooltip)
end

do
	-- RegisterProxySetting will run the GetValue and SetValue
	-- callbacks whenever access to the setting is required.
	local name = "Dropped By Location List Limit"
	local variable = "WDIGIC_LocationListLimitDroppedBy_Slider"
    local defaultValue = 5
    local minValue = 1
    local maxValue = 30
    local step = 1

	local function GetValue()
		return WDIGI_APP_SETTINGS.WDIGI_LocationListLimitDroppedBy_Slider or defaultValue
	end

	local function SetValue(value)
		WDIGI_APP_SETTINGS.WDIGI_LocationListLimitDroppedBy_Slider = value
	end

	local setting = Settings.RegisterProxySetting(category, variable, type(defaultValue), name, defaultValue, GetValue, SetValue)
	setting:SetValueChangedCallback(OnSettingChanged)

	local tooltip = "How many 'dropped by' locations should be shown in the Item Tooltip"
    local options = Settings.CreateSliderOptions(minValue, maxValue, step)
    options:SetLabelFormatter(MinimalSliderWithSteppersMixin.Label.Right);
    Settings.CreateSlider(category, setting, options, tooltip)
end

do
	-- RegisterProxySetting will run the GetValue and SetValue
	-- callbacks whenever access to the setting is required.
	local name = "Sold By Location List Limit"
	local variable = "WDIGIC_LocationListLimitSoldBy_Slider"
    local defaultValue = 5
    local minValue = 1
    local maxValue = 30
    local step = 1

	local function GetValue()
		return WDIGI_APP_SETTINGS.WDIGI_LocationListLimitSoldBy_Slider or defaultValue
	end

	local function SetValue(value)
		WDIGI_APP_SETTINGS.WDIGI_LocationListLimitSoldBy_Slider = value
	end

	local setting = Settings.RegisterProxySetting(category, variable, type(defaultValue), name, defaultValue, GetValue, SetValue)
	setting:SetValueChangedCallback(OnSettingChanged)

	local tooltip = "How many 'sold by' locations should be shown in the Item Tooltip"
    local options = Settings.CreateSliderOptions(minValue, maxValue, step)
    options:SetLabelFormatter(MinimalSliderWithSteppersMixin.Label.Right);
    Settings.CreateSlider(category, setting, options, tooltip)
end

Settings.RegisterAddOnCategory(category)