local log = require("ltex_extra.src.log")

local M = {}

local default_opts = {
    load_langs = { "nl-BE", "en-US" },
    init_check = true,
}

M.opts = {}

local ltex_languages = {
    "en-US",
    "en-GB",
    "nl-BE",
    "fr",
    "auto",
}

local register_user_cmds = function()
    vim.api.nvim_create_user_command("LtexSwitchLang", function()
        vim.ui.select(ltex_languages, {
            prompt = "Select language:",
        }, function(choice)
            require("ltex_extra.src.commands-lsp").switchLanguage(choice)
        end)
    end, { desc = "ltex_extra.nvim: Switch sever language" })
end

M.setup = function(opts)
    log.trace("Merge options")
    M.opts = opts or default_opts
    for key, value in pairs(default_opts) do
        if not M.opts[key] then
            M.opts[key] = value
        end
    end

    log.trace("Add commands to lsp")
    register_user_cmds()
    vim.lsp.commands['_ltex.addToDictionary']    = require("ltex_extra.src.commands-lsp").addToDictionary
    vim.lsp.commands['_ltex.hideFalsePositives'] = require("ltex_extra.src.commands-lsp").hideFalsePositives
    vim.lsp.commands['_ltex.disableRules']       = require("ltex_extra.src.commands-lsp").disableRules

    log.trace("Inital load files")
    if opts.init_check == true then
        require("ltex_extra.src.commands-lsp").updateConfigFull(opts.load_langs)
    end
end

return M
