local function import(name)
    return function()
        require(name)
    end
end

return {
    {
        'nvim-mini/mini.nvim',
        version = false
    },

    {
        "RRethy/base16-nvim",
    },

    {
        "vim-airline/vim-airline",
        dependencies = {
            "ryanoasis/vim-devicons",
        },
    },

    {
        "mustache/vim-mustache-handlebars",
    },

    {
        "whonore/Coqtail",
    },

    {
        "Julian/lean.nvim",
        dependencies = {
            "nvim-lua/plenary.nvim",
        },
        config = function()
            import("lean")
            vim.g.lean_config = { opts = { mappings = true } }
        end,
    },

    {
        "noir-lang/noir-nvim",
    },

    {
        "nvim-treesitter/nvim-treesitter",
        lazy = false,
        version = false,
        build = function()
            vim.cmd(":TSUpdate")
        end,
        opts = {
            highlight = {
                enable = true,
                disable = { "sage", "sage.python", "ipkg", "markdown", "md" }
            },
            indent = {
                enable = true,
                disable = { "sage", "sage.python", "markdown", "md" }
            },
            ensure_installed = "all",
            ignore_install = { "sage", "sage.python", "ipkg", "markdown", "md" },
        },
    },

    {
        "petRUShka/vim-sage",
    },

    {
        "evanleck/vim-svelte",
    },

    {
        "wuelnerdotexe/vim-astro",
    },

    {
        "tpope/vim-fugitive",
        config = function()
            local map = vim.api.nvim_set_keymap
            map('n', '<Leader>g', '<Cmd>Git<CR>', { noremap = true })
        end,
    },

    {
        "tpope/vim-surround",
    },

    {
        "tpope/vim-repeat",
    },

    {
        "nvim-lua/plenary.nvim",
    },

    {
        "lewis6991/gitsigns.nvim",
        dependencies = {
            "nvim-lua/plenary.nvim",
        },
        config = function()
            require('gitsigns').setup {
                signs = {
                    add = {
                        text = '│',
                    },
                    change = {
                        text = '│',
                    },
                    delete = {
                        text = '_',
                    },
                    topdelete = {
                        text = '‾',
                    },
                    changedelete = {
                        text = '~',
                    },
                },
            }
        end,
    },

    {
        "akinsho/flutter-tools.nvim",
        dependencies = {
            "nvim-lua/plenary.nvim",
        },
        config = function()
            require('flutter-tools').setup {
                -- lsp = {
                --     color = {
                --         enabled = false
                --     }
                -- }
            }
        end,
    },

    {
        "numToStr/Comment.nvim",
        config = function()
            local map = vim.api.nvim_set_keymap

            require('Comment').setup({})

            map(
                'n',
                '<C-_>',
                '<Cmd>lua require("Comment.api").toggle_linewise_op(vim.fn.visualmode())<CR>',
                { noremap = true, silent = true }
            )
        end,
    },

    {
        "nvim-telescope/telescope.nvim",
        dependencies = {
            "nvim-lua/plenary.nvim",

            {
                "nvim-telescope/telescope-fzf-native.nvim",
                build = "make",
            },

            "nvim-telescope/telescope-symbols.nvim",
        },
        config = import("tel"),
    },

    {
        "stevearc/dressing.nvim",
        config = function()
            require('dressing').setup({
                input = {
                    default_prompt = '❯',
                    win_options = {
                        winhighlight = 'NormalFloat:Normal',
                    },
                },
            })

            vim.cmd [[highlight link FloatTitle NonText]]
            vim.cmd [[highlight link DressingInputText Normal]]
        end,
    },

    {
        "antoinemadec/FixCursorHold.nvim",
        config = function()
            vim.g.cursorhold_updatetime = 500
        end,
    },

    {
        "sirver/ultisnips",
        ft = { 'latex', 'plaintex', 'tex' },

        config = function()
            vim.g.UltiSnipsExpandTrigger = '<tab>'
            vim.g.UltiSnipsJumpForwardTrigger = '<C-h>'
            vim.g.UltiSnipsJumpBackwardTrigger = '<C-b>'
        end,
    },

    {
        "ms-jpq/coq.artifacts",
        branch = "artifacts",
        lazy = false
    },

    {
        "ms-jpq/coq_nvim",
        branch = "coq",
        lazy = false,
        dependencies = {
            {
                "ms-jpq/coq.artifacts",
                branch = "artifacts",
                lazy = false,
            },
            {
                "ms-jpq/coq.thirdparty",
                branch = "3p",
                lazy = false,
            },
        },
        init = function()
            vim.g.coq_settings = {
                -- auto_start = 'shut-up',
                keymap = {
                    eval_snips = "<Leader>se",
                },
                -- match = {
                --     look_ahead = 1,
                -- },
                clients = {
                    snippets = {
                        always_on_top = true,
                        enabled = true,
                        weight_adjust = 100,
                    },
                    buffers = {
                        enabled = true,
                        weight_adjust = -2.0,
                    },
                    tree_sitter = {
                        enabled = true,
                        weight_adjust = -1.5,
                    },
                    lsp = {
                        enabled = true,
                        weight_adjust = -100,
                    },
                    third_party = {
                        enabled = true,
                        weight_adjust = -1.5,
                    }
                }
            }

            require('coq_3p') {
                { src = 'vimtex',  short_name = 'TEX' },
                { src = 'nvimlua', short_name = 'NLUA', conf_only = true },
                { src = 'bc',      short_name = 'CALC', precision = 8 },
            }
        end,
        build = function()
            require("coq")
            vim.cmd(":COQdeps")
        end,
        config = function()
            require('coq_3p') {
                { src = 'vimtex',  short_name = 'TEX' },
                { src = 'nvimlua', short_name = 'NLUA', conf_only = true },
                { src = 'bc',      short_name = 'CALC', precision = 8 },
            }
        end
    },

    {
        "ms-jpq/coq.thirdparty",
        branch = "3p",
        lazy = false,
    },

    {
        "nvim-lua/lsp-status.nvim",
        lazy = false,
    },

    {
        "neovim/nvim-lspconfig",
        lazy = false,

        dependencies = {
            {
                "nvim-lua/lsp-status.nvim",
                lazy = false,
            },

            {
                "ms-jpq/coq.thirdparty",
                branch = "3p",
                lazy = false,
            },

            {
                "ms-jpq/coq.artifacts",
                branch = "artifacts",
                lazy = false,
            },

            {
                "ms-jpq/coq_nvim",
                branch = "coq",
                lazy = false,

                dependencies = {
                    {
                        "ms-jpq/coq.artifacts",
                        branch = "artifacts",
                        lazy = false,
                    },
                },
            },
        },

        config = function()
            local capabilities = require("coq").lsp_ensure_capabilities()
            -- extend coq completion capabilities all lsps
            vim.lsp.config('*', {
                capabilities = capabilities,
            })
            vim.lsp.enable("lua_ls")
            require("lsp")
        end,
    },

    {
        "lervag/vimtex",

        config = function()
            vim.g.vimtex_view_general_viewer = 'zathura'
            vim.g.vimtex_compiler_method = "latexmk"

            -- vim.g.vimtex_view_general_options = = '-x nvim -n -c "Vimtex'
            -- 'file:@pdf\\#src:@line@tex'
            -- vim.g.vimtex_quickfix_enabled = 0
            -- vim.g.Tex_GotoError = 0
            -- vim.g.Tex_ShowErrorContext = 0
        end,
    },

    {
        "iamcco/markdown-preview.nvim",

        ft = { "markdown" },

        init = function()
            vim.g.mkdp_filetypes = { "markdown" }
        end,

        build = function()
            vim.fn.system("cd app && npm install")
        end,

        config = function()
            local map = vim.api.nvim_set_keymap

            map('n', '<C-m>', '<Plug>MarkdownPreviewToggle', {})
            map('n', '<Leader>m', '<Plug>MarkdownPreviewToggle', {})

            vim.g.mkdp_markdown_css =
                os.getenv("HOME") .. "/.config/nvim/lua/markdownStyle.css"

            vim.g.mkdp_highlight_css =
                os.getenv("HOME") .. "/.cache/wal/colors.css"
        end,
    },
    {
        'kkrampis/codex.nvim',
        lazy = true,
        cmd = { 'Codex', 'CodexToggle' }, -- Optional: Load only on command execution
        keys = {
            {
                '<leader>cc', -- Change this to your preferred keybinding
                function() require('codex').toggle() end,
                desc = 'Toggle Codex popup or side-panel',
                mode = { 'n', 't' }
            },
        },
        opts = {
            keymaps     = {
                toggle = nil,        -- Keybind to toggle Codex window (Disabled by default, watch out for conflicts)
                quit = '<C-q>',      -- Keybind to close the Codex window (default: Ctrl + q)
            },                       -- Disable internal default keymap (<leader>cc -> :CodexToggle)
            border      = 'rounded', -- Options: 'single', 'double', or 'rounded'
            width       = 0.8,       -- Width of the floating window (0.0 to 1.0)
            height      = 0.8,       -- Height of the floating window (0.0 to 1.0)
            model       = nil,       -- Optional: pass a string to use a specific model (e.g., 'o3-mini')
            autoinstall = true,      -- Automatically install the Codex CLI if not found
            panel       = false,     -- Open Codex in a side-panel (vertical split) instead of floating window
            use_buffer  = false,     -- Capture Codex stdout into a normal buffer instead of a terminal buffer
        },
    },
    {
        "coder/claudecode.nvim",
        dependencies = { "folke/snacks.nvim" },
        config = true,
        -- `cmd` lets lazy.nvim create command stubs that load the plugin on first use,
        -- so `:ClaudeCode` and friends work on a fresh start. Without it, a keys-only
        -- spec defers loading until a <leader>a* mapping is pressed and the commands
        -- would not exist yet.
        cmd = {
            "ClaudeCode",
            "ClaudeCodeFocus",
            "ClaudeCodeSelectModel",
            "ClaudeCodeAdd",
            "ClaudeCodeSend",
            "ClaudeCodeTreeAdd",
            "ClaudeCodeStatus",
            "ClaudeCodeStart",
            "ClaudeCodeStop",
            "ClaudeCodeOpen",
            "ClaudeCodeClose",
            "ClaudeCodeDiffAccept",
            "ClaudeCodeDiffDeny",
            "ClaudeCodeCloseAllDiffs",
        },
        keys = {
            { "<leader>a",  nil,                              desc = "AI/Claude Code" },
            { "<leader>ac", "<cmd>ClaudeCode<cr>",            desc = "Toggle Claude" },
            { "<leader>af", "<cmd>ClaudeCodeFocus<cr>",       desc = "Focus Claude" },
            { "<leader>ar", "<cmd>ClaudeCode --resume<cr>",   desc = "Resume Claude" },
            { "<leader>aC", "<cmd>ClaudeCode --continue<cr>", desc = "Continue Claude" },
            { "<leader>am", "<cmd>ClaudeCodeSelectModel<cr>", desc = "Select Claude model" },
            { "<leader>ab", "<cmd>ClaudeCodeAdd %<cr>",       desc = "Add current buffer" },
            { "<leader>as", "<cmd>ClaudeCodeSend<cr>",        mode = "v",                  desc = "Send to Claude" },
            {
                "<leader>as",
                "<cmd>ClaudeCodeTreeAdd<cr>",
                desc = "Add file",
                ft = { "NvimTree", "neo-tree", "oil", "minifiles", "netrw", "snacks_picker_list" },
            },
            -- Diff management
            { "<leader>aa", "<cmd>ClaudeCodeDiffAccept<cr>", desc = "Accept diff" },
            { "<leader>ad", "<cmd>ClaudeCodeDiffDeny<cr>",   desc = "Deny diff" },
        },
    }
}
