---------------------------
-- Notification Provider --
---------------------------
local AddOnName, nsVars = ...
local ss = nsVars.SS

local table, pairs = table, pairs
local CreateFrame, UIParent = CreateFrame, UIParent

local frame

local createFrame = function()
    local frm = CreateFrame("Frame", ss._f.."Notification",UIParent)
    frm:SetWidth(400)
    frm:SetHeight(200)
    frm:SetPoint("CENTER", 0, 0)

    frm.title = frm:CreateFontString(ss._f.."NotificationTitle")
    frm.title:SetFont     (ss.private.font["general"], 14)
    frm.title:SetPoint    ("TOP", 0, -5)
    frm.title:SetSize     (350, 100)
    frm.title:SetJustifyV ("TOP")

    frm.content = frm:CreateFontString(ss._f.."NotificationContent")
    frm.content:SetFont     (ss.private.font["general"], 14)
    frm.content:SetPoint    ("BOTTOM", 0, 50)
    frm.content:SetSize     (350, 100)
    frm.content:SetJustifyV ("BOTTOM")
    frm.content:SetJustifyH ("LEFT")

    frm.close = CreateFrame("Button", ss._f.."NotificationClose", frm, "GameMenuButtonTemplate")
    frm.close:SetSize  (75, 25)
    frm.close:SetPoint ("Bottom Right", 0, 5)
    frm.close:SetText  ("Close")
    frm.close:SetScript("OnClick", function()
        frm:Hide()
    end)

    return frm
end

local postNotification = function(content)
    frame = frame or createFrame()
    frame.content:SetText(content)
    frame:Show()
end

local mtNotification = {};


function mtNotification:Notify(content)
    if content then
        postNotification(content)
    elseif self.queue then
        local completed = {}
        for k,v in pairs(self.queue) do
            ss.Debug.describe({k, v})
            completed[k] = v
        end
        for k,v in pairs(completed) do
            table.remove(self.queue, k)
        end

    end
end

function mtNotification:Queue(content)
    self.queue = self.queue or {}
    table.insert(self.queue, content)
end

ss["Notification"] = setmetatable( {}, { __index = mtNotification } );
