--[[
Author: Jarth
Filename: SummonAssistant.lua
]] --

-------------------------------------------------------------------------------------------------
-- VARIABLES --
-------------------------------------------------------------------------------------------------
local SummonAssistant = SummonAssistant

-------------------------------------------------------------------------------------------------
-- FUNCTIONS --
-------------------------------------------------------------------------------------------------
function SummonAssistant.OnAddOnLoaded(_, addonName)
    if addonName == SummonAssistant.Addon.Name then
        SummonAssistant.Initialize()
    end
end

function SummonAssistant.Initialize()
    -- Load saved values..
    SummonAssistant.Saved = ZO_SavedVars:New("SummonAssistant_Character", SummonAssistant.Addon.Version, nil, SummonAssistant.Default)
    if SummonAssistant.Saved.UseAccountSettings then
        SummonAssistant.Saved = ZO_SavedVars:NewAccountWide("SummonAssistant_Account", SummonAssistant.Addon.Version, nil, SummonAssistant.Default)
    end

    SummonAssistant:RestorePanel()
    SummonAssistant:HoykeyCreateSelections()
    SummonAssistant:CreateSettingsWindow()

    EVENT_MANAGER:UnregisterForEvent(SummonAssistant.Addon.Name, EVENT_ADD_ON_LOADED)
end

-------------------------------------------------------------------------------------------------
-- PRIVATE FUNCTIONS --
-------------------------------------------------------------------------------------------------
function SummonAssistant:GetVersion(showMinor)
    if showMinor == false or SummonAssistant.Addon.MinorVersion == nil then
        return tostring(SummonAssistant.Addon.Version)
    end
    return tostring(SummonAssistant.Addon.Version) .. "." .. tostring(SummonAssistant.Addon.MinorVersion)
end

function SummonAssistant:RestorePanel()
    SummonAssistant:SetFragmentBehaviour()

    SummonAssistant:SetButtonFrameWidth()

    SummonAssistant:InitializeButtons()

    SummonAssistant:ButtonsBackdropColor()

    SummonAssistant:RestorePosition()

    SummonAssistant:UpdateMoveFrame()
end

function SummonAssistant:RestorePosition()
    local Top = SummonAssistant.Saved.Top
    local Left = SummonAssistant.Saved.Left
    SummonAssistant_Frame:ClearAnchors()
    SummonAssistant_Frame:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, Left, Top)
end

EVENT_MANAGER:RegisterForEvent(SummonAssistant.Addon.Name, EVENT_ADD_ON_LOADED, SummonAssistant.OnAddOnLoaded)