-- Auto-load the plugin if not disabled
if vim.g.loaded_nvim_ctagtap then
    return
end

-- Mark as loaded
vim.g.loaded_nvim_ctagtap = 1

-- Create user commands
vim.api.nvim_create_user_command("CtagTapEnable", function()
    require("nvim-ctagtap").enable()
end, { desc = "Enable tag browser mouse navigation" })

vim.api.nvim_create_user_command("CtagTapDisable", function()
    require("nvim-ctagtap").disable()
end, { desc = "Disable tag browser mouse navigation" })

vim.api.nvim_create_user_command("CtagTapToggle", function()
    local tb = require("nvim-ctagtap")
    local enabled = tb.toggle()
    if enabled then
        vim.notify("Tag browser enabled", vim.log.levels.INFO)
    else
        vim.notify("Tag browser disabled", vim.log.levels.INFO)
    end
end, { desc = "Toggle tag browser mouse navigation" })

vim.api.nvim_create_user_command("CtagTapHistory", function()
    require("nvim-ctagtap").show_history()
end, { desc = "Show tag browser navigation history" })

vim.api.nvim_create_user_command("CtagTapClearHistory", function()
    require("nvim-ctagtap").clear_history()
end, { desc = "Clear tag browser navigation history" })

-- Auto-enable if configured
if vim.g.nvim_ctagtap_auto_enable ~= false then
    vim.defer_fn(function()
        require("nvim-ctagtap").setup()
    end, 0)
end
