-- telescope.lua: Highly extensible fuzzy finder for files, code, and plugins.

return {
  {
    "nvim-telescope/telescope-ui-select.nvim",
  },
  {
    "nvim-telescope/telescope.nvim",
    -- tag = "0.1.5",
    dependencies = { "nvim-lua/plenary.nvim" },
    config = function()
      require("telescope").setup({
        extensions = {
          ["ui-select"] = {
            require("telescope.themes").get_dropdown({}),
          },
        },
      })
      local builtin = require("telescope.builtin")
      vim.keymap.set("n", "<C-p>", builtin.find_files, {})
      vim.keymap.set("n", "<leader>fg", builtin.live_grep, {})
      -- vim.keymap.set("n", "<leader><leader>", builtin.oldfiles, {})
      vim.keymap.set("n", "<leader><leader>", function()
        require("telescope.builtin").find_files()
      end, { desc = "Find files", noremap = true, silent = true })
      vim.keymap.set("n", "z=", function()
        builtin.spell_suggest(require("telescope.themes").get_cursor({}))
      end, {})
      -- Live grep (search in files)
      vim.keymap.set("n", "<leader>fg", builtin.live_grep, {})

      -- Grep word under cursor
      vim.keymap.set("n", "<leader>fw", builtin.grep_string, {})

      -- Buffers
      vim.keymap.set("n", "<leader>fb", builtin.buffers, {})
      vim.keymap.set("n", "<leader>bb", builtin.buffers, {})

      -- Recent files
      vim.keymap.set("n", "<leader>fr", builtin.oldfiles, {})

      -- Find in current buffer
      vim.keymap.set("n", "<leader>/", builtin.current_buffer_fuzzy_find, {})

      -- Help tags
      vim.keymap.set("n", "<leader>fh", builtin.help_tags, {})

      -- Commands
      vim.keymap.set("n", "<leader>fc", builtin.commands, {})

      -- Keymaps
      vim.keymap.set("n", "<leader>fk", builtin.keymaps, {})

      -- Git status
      vim.keymap.set("n", "<leader>gs", builtin.git_status, {})

      -- Git branches
      vim.keymap.set("n", "<leader>gb", builtin.git_branches, {})

      -- Git commits
      vim.keymap.set("n", "<leader>gC", builtin.git_commits, {})

      -- LSP document symbols
      vim.keymap.set("n", "<leader>fs", builtin.lsp_document_symbols, {})

      -- LSP workspace symbols
      vim.keymap.set("n", "<leader>fS", builtin.lsp_workspace_symbols, {})

      -- Diagnostics
      vim.keymap.set("n", "<leader>fD", builtin.diagnostics, {})

      -- Resume last picker
      vim.keymap.set("n", "<leader>f.", builtin.resume, {})

      -- Colorschemes
      vim.keymap.set("n", "<leader>ft", builtin.colorscheme, {})

      -- Vim options
      vim.keymap.set("n", "<leader>fo", builtin.vim_options, {})

      -- Marks
      vim.keymap.set("n", "<leader>fm", builtin.marks, {})

      -- Registers
      vim.keymap.set("n", "<leader>fR", builtin.registers, {})

      -- Jump list
      vim.keymap.set("n", "<leader>fj", builtin.jumplist, {})
      require("telescope").load_extension("ui-select")
      require("telescope").load_extension("noice")
    end,
  },
}
