-- Standalone options (migrated from NvChad)

local opt = vim.opt
local o = vim.o
local g = vim.g

-- UI
o.laststatus = 3        -- Global statusline
o.showmode = false      -- Don't show mode (statusline handles it)
o.cursorline = true     -- Highlight current line
o.cursorlineopt = "number"  -- Only highlight line number

-- Clipboard
o.clipboard = "unnamedplus"  -- Use system clipboard

-- Indenting
o.expandtab = true      -- Use spaces instead of tabs
o.shiftwidth = 2        -- Indent width
o.smartindent = true    -- Smart autoindenting
o.tabstop = 2          -- Tab width
o.softtabstop = 2      -- Backspace removes 2 spaces

-- UI elements
opt.fillchars = { eob = " " }  -- Hide ~ on empty lines
o.ignorecase = true     -- Ignore case in search
o.smartcase = true      -- Case-sensitive if uppercase in search
o.mouse = "a"          -- Enable mouse

-- Numbers
o.number = true         -- Show line numbers
o.numberwidth = 2       -- Line number column width
o.ruler = false         -- Don't show cursor position (statusline handles it)

-- Disable nvim intro
opt.shortmess:append "sI"

-- Sign column
o.signcolumn = "yes"    -- Always show sign column

-- Splits
o.splitbelow = true     -- Horizontal splits go below
o.splitright = true     -- Vertical splits go right

-- Timeouts
o.timeoutlen = 400      -- Time to wait for mapped sequence

-- Files
local undodir = vim.fn.stdpath "state" .. "/undo"
vim.fn.mkdir(undodir, "p")  -- Create undodir if it doesn't exist
o.undodir = undodir       -- Set explicit undo directory
o.undofile = true         -- Persistent undo

-- Resolve symlinks for undo history consistency
vim.api.nvim_create_autocmd("BufReadPost", {
  callback = function()
    local current_path = vim.fn.expand "%:p"
    local resolved_path = vim.fn.resolve(current_path)
    if resolved_path ~= current_path then
      local resolved_undofile = vim.fn.undofile(resolved_path)
      if vim.fn.filereadable(resolved_undofile) == 1 then
        -- Load undo from the resolved (real) path
        vim.cmd("set undofile")
        vim.cmd("call undofile('" .. resolved_undofile .. "')")
      end
    end
  end,
})

-- Update time (used by gitsigns and swap file)
o.updatetime = 250

-- Navigation
opt.whichwrap:append "<>[]hl"  -- Move to next/prev line with these keys

-- Disable unused providers (performance)
g.loaded_node_provider = 0
g.loaded_python3_provider = 0
g.loaded_perl_provider = 0
g.loaded_ruby_provider = 0

-- Add Mason binaries to PATH
local is_windows = vim.fn.has "win32" ~= 0
local sep = is_windows and "\\" or "/"
local delim = is_windows and ";" or ":"
vim.env.PATH = table.concat({ vim.fn.stdpath "data", "mason", "bin" }, sep) .. delim .. vim.env.PATH

-- User overrides
o.scrolloff = 10  -- Keep 10 lines visible above/below cursor

-- Experimental: improved command-line and message UI
pcall(function() require('vim._core.ui2').enable() end)
