local _, Orbit = ...
local L = Orbit.L
local OrbitEngine = Orbit.Engine

-- [ CONSTANTS ] -------------------------------------------------------------------------------------
local SYSTEM_ID = "Orbit_Datatexts"
local POSITION_RESTORE_DELAY = 0.5

-- [ NAMESPACE ] -------------------------------------------------------------------------------------
Orbit.Datatexts = Orbit.Datatexts or {}

-- [ PLUGIN REGISTRATION ] ---------------------------------------------------------------------------
local Plugin = Orbit:RegisterPlugin("Datatexts", SYSTEM_ID, {
    displayName = L.PLG_NAME_DATATEXTS,
    liveToggle = true,
    defaults = {
        datatextPositions = {},
    },
})

-- [ LIFECYCLE ] -------------------------------------------------------------------------------------
function Plugin:OnLoad()
    local DT = Orbit.Datatexts
    DT.DrawerUI:CreateCornerTriggers()
    C_Timer.After(POSITION_RESTORE_DELAY, function() DT.DatatextManager:RestorePositions() end)
end

function Plugin:OnDisable()
    local DT = Orbit.Datatexts
    DT.DrawerUI:Suspend()
    DT.DatatextManager:DisableAll()
    self.suspended = true
end

function Plugin:ApplySettings()
    local DT = Orbit.Datatexts
    if self.suspended then
        self.suspended = false
        DT.DrawerUI:Resume()
        DT.DatatextManager:RestorePositions()
    end
    DT.DatatextManager:UpdateAllDatatexts()
end
