-- core.lua
local ADDON, ns = ...
local Core = {}
ns.Core = Core

-- Defaults
MagicTranslatorDB = MagicTranslatorDB or {}
local defaults = {
  enabled = true,
  useMorphologicalAnalysis = true,
  showCyrlicInfo = false,
  src = "en",
  dst = "ru",
  mode = "phrases-first", -- words-only | phrases-first | transparent
  highlightColor = { r = 0.2, g = 0.8, b = 0.4 },
  logLevel = "info", -- debug | info | warn | error
}

local function ApplyDefaults()
  for k, v in pairs(defaults) do
    if MagicTranslatorDB[k] == nil then MagicTranslatorDB[k] = v end
  end
end

function Core:OnInitialize()
  ApplyDefaults()
  ns.Dictionary:BuildIndex(MagicTranslatorDB.src, MagicTranslatorDB.dst)
      print("Dictionary index builded")
  ns.ChatFilter:Register()
      print("Chat filer registered")
  ns.UI:Init()
  ns.Logger:Info("Initialized", { mode = MagicTranslatorDB.mode })
end

local frame = CreateFrame("Frame")
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(_, event, name)
  if name == "Magic Translator" or name == ADDON then

    print("Magic Translator Addon Loaded")

    Core:OnInitialize()
  end
end)

SLASH_CLEARCHAT1 = "/clear"
SlashCmdList.CLEARCHAT = function()
  DEFAULT_CHAT_FRAME:Clear()
end
