-- ~/.config/nvim/lua/plugins/blink.lua
return {
  "saghen/blink.cmp",
  version      = "1.*",
  build        = "cargo build --release",
  lazy         = false,

  dependencies = {
    "L3MON4D3/LuaSnip",
    "rafamadriz/friendly-snippets",
  },

  opts         = {
    fuzzy      = { implementation = "prefer_rust" },

    sources    = {
      min_keyword_length = 1,
      default = { "lsp", "snippets", "buffer", "path" },
      providers = {
        lsp = { name = "LSP", opts = { max_items = 200, score_offset = 0 } },
        buffer = { name = "Buffer", opts = { max_items = 100 } },
      },
      per_filetype = {
        lua = { default = { "lazydev", "lsp", "snippets", "buffer", "path" } },
      },
    },

    completion = {
      accept = { auto_brackets = { enabled = true } },
      trigger = { show_on_trigger_character = true },
      list = { selection = "auto_insert" },
      documentation = { auto_show = true, auto_show_delay_ms = 200 },
      ghost_text = { enabled = true },
    },

    signature  = { enabled = true, window = { border = "rounded" } },
    cmdline    = { enabled = false },

    -- Tab cycles through items and accepts
    keymap     = {
      preset = "enter",
      ["<Tab>"] = {
        "select_next",
        "accept",
        "snippet_forward",
        "fallback",
      },
      ["<S-Tab>"] = {
        "select_prev",
        "snippet_backward",
        "fallback",
      },
      ["<CR>"] = { "accept", "fallback" },
    },
  },

  config       = function(_, opts)
    require("blink.cmp").setup(opts)
  end,
}
