-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable", -- latest stable release
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

-- Install Plugins
require('lazy').setup({
    -- LSP
    'luukvbaal/nnn.nvim',
    'nvim-tree/nvim-tree.lua',
    'nvim-telescope/telescope.nvim',
    'nvim-telescope/telescope-ui-select.nvim',
    {
        "nvim-orgmode/orgmode",
        dependencies = {
            "lukas-reineke/headlines.nvim",
        },
        event = 'VeryLazy',
        ft = { 'org' },
        config = function()
            require("orgmode").setup({
                org_startup_indented = true, -- ← this gives Emacs-style virtual indentation under headings (huge for legibility)
                org_agenda_files = '~/org/**/*',
                org_default_notes_file = '~/org/scratch.org',
                org_startup_indented = true,
                org_deadline_warning_days = 0,
                org_agenda_custom_commands = {
                    w = {
                        description = "Work",
                        types = {
                            {
                                type = 'agenda',
                                org_agenda_tag_filter_preset = 'work'
                            }
                        }
                    },
                    p = {
                        description = "Personal",
                        types = {
                            {
                                type = 'agenda',
                                org_agenda_tag_filter_preset = 'personal'
                            }
                        }
                    },
                }
            })

            require("headlines").setup({
                org = {
                    fat_headlines = false, -- ← no more huge blocks
                    headline_highlights = { "Headline1", "Headline2", "Headline3", "Headline4" },
                    quote_string = "│", -- thinner vertical bar for quotes (optional but nicer)
                    quote_highlight = "Quote",
                },
            })

        end,
    },
})

-- Initialize Plugins
require('nnn').setup({
    picker = {
        cmd = "nnn -C",
        style = { border = "rounded" },
        fullscreen = false,
    },
})
local function tree_on_attach(bufnr)
    local api = require('nvim-tree.api')
    api.config.mappings.default_on_attach(bufnr)
    vim.keymap.del('n', '<C-e>', { buffer = bufnr })
    vim.keymap.set("n", "<M-h>", function() api.tree.resize({ relative = -5 }) end, { buffer = bufnr })
    vim.keymap.set("n", "<M-l>", function() api.tree.resize({ relative = 5 }) end, { buffer = bufnr })
end
require('nvim-tree').setup({
    on_attach = tree_on_attach,
    view = {
        side = "left",
    },
    tab = {
        sync = {
            open  = true,
            close = true,
        },
    },
})
require('telescope').setup({
    defaults = {
        file_ignore_patterns = {
            "%.git/",
            "node_modules/",
            "%.DS_Store",
        },
    },
    pickers = {
        find_files = {
            hidden = true,
            no_ignore = true,
        },
    },
})
require("telescope").load_extension("ui-select")
