-- :NeoCodeium chat - opens browser with the Windsurf Chat
-- :NeoCodeium restart - restarts the server (useful if the server stops responding for any reason).
-- :NeoCodeium toggle_buffer - toggles NeoCodeium completion in the current buffer.
-- :NeoCodeium[!] toggle - toggles NeoCodeium completion. Convey the bang to disable command.

return {
    'monkoose/neocodeium',
    event = 'VeryLazy',
    config = function()
        local neocodeium = require 'neocodeium'
        neocodeium.setup {
            filter = function(bufnr)
                -- отключаем в .env по имени файла
                local name = vim.api.nvim_buf_get_name(bufnr)
                if vim.endswith(name, '.env') then
                    return false
                end

                -- включаю в конкретных файлах
                -- узнать filetype можно через `:set filetype?`
                local ft = vim.bo[bufnr].filetype
                if ft == 'go' or ft == 'rs' then
                    return true
                end
                return false
            end,
        }

        -- Бинды (в insert mode) ('<A-' и '<M-' это оба 'Alt')
        vim.keymap.set('i', '<A-Tab>', neocodeium.accept, { desc = 'Accept NeoCodeium suggestion' })
        vim.keymap.set('i', '<A-c>', neocodeium.clear, { desc = 'Clear suggestion' })

        vim.keymap.set('i', '<A-Right>', neocodeium.accept_word, { desc = 'Accept next word (NeoCodeium)' })
        vim.keymap.set('i', '<A-Left>', neocodeium.accept_line, { desc = 'Accept next line (NeoCodeium)' })

        vim.keymap.set('i', '<A-l>', neocodeium.accept_word, { desc = 'Accept next word (h j k l style)' })
        vim.keymap.set('i', '<A-h>', neocodeium.accept_line, { desc = 'Accept next line (h j k l style)' })
    end,
}
