-- fzf.lua: Integrates fuzzy Finder for quick file, buffer, and command searching.

return {
  {
    "ibhagwan/fzf-lua",
    dependencies = { "nvim-tree/nvim-web-devicons" },
    ---@module "fzf-lua"
    ---@type fzf-lua.Config|{}
    ---@diagnostics disable: missing-fields
    config = function()
      require("fzf-lua").setup({
        -- Use Telescope-like defaults
        "telescope",

        winopts = {
          height = 0.85,
          width = 0.80,
          row = 0.35,
          col = 0.50,
          border = "rounded",
          preview = {
            layout = "flex",
            flip_columns = 120,
            vertical = "down:45%",
            horizontal = "right:50%",
          },
        },

        files = {
          prompt = "Files❯ ",
          git_icons = true,
          file_icons = true,
          color_icons = true,
        },

        grep = {
          prompt = "Rg❯ ",
          input_prompt = "Grep For❯ ",
          git_icons = true,
          file_icons = true,
          color_icons = true,
        },
      })
    end,
    ---@diagnostics enable: missing-fields

    keys = {
      -- Files
      { "<leader>ff", "<cmd>FzfLua files<cr>", desc = "Find Files" },
      { "<leader>fr", "<cmd>FzfLua oldfiles<cr>", desc = "Recent Files" },
      { "<C-p>", "<cmd>FzfLua files<cr>", desc = "Find Files" },

      -- Search
      { "<leader>fg", "<cmd>FzfLua live_grep<cr>", desc = "Live Grep" },
      { "<leader>fw", "<cmd>FzfLua grep_cword<cr>", desc = "Grep Word" },
      { "<leader>fW", "<cmd>FzfLua grep_cWORD<cr>", desc = "Grep WORD" },

      -- Buffers
      { "<leader>fb", "<cmd>FzfLua buffers<cr>", desc = "Buffers" },
      -- { "<leader><leader>", "<cmd>FzfLua buffers<cr>", desc = "Buffers" },

      -- Git
      { "<leader>gC", "<cmd>FzfLua git_commits<cr>", desc = "Git Commits" },
      { "<leader>gR", "<cmd>FzfLua git_files<cr>", desc = "Git Files" },
      { "<leader>gS", "<cmd>FzfLua git_status<cr>", desc = "Git Status" },

      -- LSP
      { "<leader>ld", "<cmd>FzfLua lsp_document_symbols<cr>", desc = "Document Symbols" },
      { "<leader>lw", "<cmd>FzfLua lsp_workspace_symbols<cr>", desc = "Workspace Symbols" },
      { "<leader>lr", "<cmd>FzfLua lsp_references<cr>", desc = "References" },
      { "<leader>la", "<cmd>FzfLua lsp_code_actions<cr>", desc = "Code Actions" },

      -- Diagnostics
      { "<leader>lD", "<cmd>FzfLua diagnostics_document<cr>", desc = "Document Diagnostics" },
      { "<leader>lW", "<cmd>FzfLua diagnostics_workspace<cr>", desc = "Workspace Diagnostics" },

      -- Help
      { "<leader>fh", "<cmd>FzfLua help_tags<cr>", desc = "Help Tags" },
      { "<leader>fc", "<cmd>FzfLua commands<cr>", desc = "Commands" },
      { "<leader>fk", "<cmd>FzfLua keymaps<cr>", desc = "Keymaps" },

      -- Misc
      { "<leader>f:", "<cmd>FzfLua command_history<cr>", desc = "Command History" },
      { "<leader>fm", "<cmd>FzfLua marks<cr>", desc = "Marks" },
    },
  },
}
