{ pkgs, ... }:

{
  programs.neovim = {
    enable = true;

    plugins = with pkgs.vimPlugins; [
      neo-tree-nvim
      catppuccin-nvim
      tokyonight-nvim
      nvim-lspconfig
      nvim-cmp
      cmp-nvim-lsp
      cmp-buffer
      cmp-path
      plenary-nvim
      telescope-nvim
      (nvim-treesitter.withAllGrammars)
      vim-nix
      lualine-nvim
    ];

    extraLuaConfig = ''
      vim.cmd("colorscheme catppuccin-mocha")
      -- Basic settings
      vim.o.number = true
      vim.o.relativenumber = true

      -- =========================
      -- LSP (Neovim 0.11+ way)
      -- =========================

      -- Add cmp capabilities
      local capabilities = require("cmp_nvim_lsp").default_capabilities()

      vim.lsp.config("nil_ls", {
        capabilities = capabilities,
      })

      -- PHP LSP
      vim.lsp.config("intelephense", {
        capabilities = capabilities,
      })

      vim.lsp.enable("intelephense")


      vim.lsp.enable("nil_ls")

      -- =========================
      -- nvim-cmp
      -- =========================

      local cmp = require("cmp")

      cmp.setup({
        mapping = cmp.mapping.preset.insert({
          ["<C-Space>"] = cmp.mapping.complete(),
          ["<CR>"] = cmp.mapping.confirm({ select = true }),
        }),
        sources = {
          { name = "nvim_lsp" },
          { name = "buffer" },
          { name = "path" },
        }
      })

      -- =========================
      -- Telescope
      -- =========================

      local builtin = require("telescope.builtin")
      vim.keymap.set("n", "<leader>ff", builtin.find_files, {})
      vim.keymap.set("n", "<leader>fg", builtin.live_grep, {})

      -- =========================
      -- Lualine (status line with Git branch)
      -- =========================
      require('lualine').setup {
        options = {
          theme = 'catppuccin',  -- match your colorscheme
          section_separators = {'', ''},
          component_separators = {'', ''},
        },
        sections = {
          lualine_a = {'mode'},
          lualine_b = {'branch'},  -- shows Git branch here
          lualine_c = {'filename'},
          lualine_x = {'encoding', 'fileformat', 'filetype'},
          lualine_y = {'progress'},
          lualine_z = {'location'}
        }
      }
    '';
  };
}
