-- Copyright (C) 2010 Tyson Brown
-- 
-- This file is part QuestHelper2, an AddOn for World of Warcraft.
-- 
-- QuestHelper2 is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
-- 
-- QuestHelper2 is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
-- 
-- You should have received a copy of the GNU General Public License
-- along with QuestHelper2. If not, see <http://www.gnu.org/licenses/>.

if LibDebug then LibDebug() end
local shared = select(2, ...)

function shared.displayFirstTimeNotice(callback)
  shared.displayFirstTimeNotice = nil
  
  local license = "GPL3"
  
  if _G.QuestHelper2_Collection_LicenseAccepted ~= license then
    
    local notice = "QuestHelper2 is free software: you can redistribute it and/or modify "..
                   "it under the terms of the GNU General Public License as published by "..
                   "the Free Software Foundation, either version 3 of the License, or "..
                   "(at your option) any later version.\n\n"..
                   "QuestHelper2 is distributed in the hope that it will be useful, "..
                   "but WITHOUT ANY WARRANTY; without even the implied warranty of "..
                   "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "..
                   "GNU General Public License for more details."
    
    -- The FSF does not recommend displaying translated versions of the GPL license...
    -- but since when have I let good advice get in the way of me doing something stupid?
    local lang = GetLocale():match("^(..)")
    
    if lang == "fr" then
      notice = "Ce programme vient SANS ABSOLUMENT AUCUNE GARANTIE. "..
               "Ceci est un logiciel libre et vous êtes invité à le "..
               "redistribuer suivant certaines conditions.\n---\n"..
               notice
    elseif lang == "es" then
      notice = "Este programa se ofrece SIN GARANTÍA ALGUNA. "..
               "Es software libre, y usted puede redistribuirlo bajo ciertas condiciones\n---\n"..
               notice
    elseif lang == "de" then
      notice = "Für dieses Programm besteht KEINERLEI GARANTIE. "..
               "Dies ist freie Software, die Sie unter bestimmten Bedingungen weitergeben dürfen.\n---\n"..
               notice
    end
    
    local frame = CreateFrame("Frame", nil, UIParent)
    
    local function accepted()
      frame:Hide()
      _G.QuestHelper2_Collection_LicenseAccepted = license
      callback()
    end
    
    local function declined()
      DisableAddOn("QuestHelper2_Collection")
      ReloadUI()
    end
    
    local bg = frame:CreateTexture(nil, "BACKGROUND")
    bg:SetAllPoints()
    bg:SetTexture(0,0,0,0.5)
    
    local text = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalCenter")
    text:SetText(notice)
    text:SetWidth(300)
    text:SetPoint("TOPLEFT", 10, -10)
    
    frame:SetWidth(300+20)
    frame:SetHeight(text:GetHeight()+20+32)
    frame:SetBackdrop({edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border.blp", 
                       edgeSize = 16, 
                       insets = {left = 4,
                                 right = 4,
                                 top = 4,
                                 bottom = 4}})
    
    local decline_btn = CreateFrame("BUTTON", nil, frame, "UIPanelButtonTemplate")
    decline_btn:SetPoint("BOTTOMLEFT", 60, 10)
    decline_btn:SetText(DECLINE)
    decline_btn:SetWidth(85)
    decline_btn:SetHeight(24)
    decline_btn:SetScript("OnClick", declined)
    
    local accept_btn = CreateFrame("BUTTON", nil, frame, "UIPanelButtonTemplate")
    accept_btn:SetPoint("BOTTOMRIGHT", -60, 10)
    accept_btn:SetText(ACCEPT)
    accept_btn:SetWidth(85)
    accept_btn:SetHeight(24)
    accept_btn:SetScript("OnClick", accepted)
    
    frame:SetPoint("CENTER")
    frame:Show()
    
    -- ACCEPT DECLINE are translated strings provided by Blizzard.
  else
    -- Accepted the license in a previous version.
    callback()
  end
end
