-- vimtex.lua: Full LaTeX editing support (compiling, viewing, and syntax).

return {
  "lervag/vimtex",
  ft = "tex",
  config = function()
    -- PDF viewer
    vim.g.vimtex_view_method = "zathura"

    -- Compiler settings
    vim.g.vimtex_compiler_latexmk = {
      continuous = 1,
      callback = 1,
      options = {
        "-pdf",
        "-shell-escape",
        "-verbose",
        "-file-line-error",
        "-synctex=1",
        "-interaction=nonstopmode",
      },
    }
    -- Concealment (makes LaTeX prettier to read)
    vim.g.vimtex_syntax_conceal = {
      accents = 1,
      math_symbols = 1,
      math_fracs = 1,
      math_super_sub = 1,
    }

    vim.g.vimtex_toc_config = {
      name = "TOC",
      layers = { "content", "todo", "include" },
      split_width = 25,
      todo_sorted = 0,
      show_help = 1,
      show_numbers = 1,
    }

    -- Don't open quickfix window automatically
    vim.g.vimtex_quickfix_mode = 0

    -- kenable folding
    vim.g.vimtex_fold_enabled = 1

    -- What to fold (customize as needed)
    vim.g.vimtex_fold_types = {
      envs = {
        enabled = 1,
        whitelist = {}, -- Empty = all environments
        blacklist = {},
      },
      sections = {
        enabled = 1,
        sections = {
          "%(add)?part",
          "%(chapter|%(sub)*section|%(sub)?paragraph)",
          "appendix",
        },
      },
      items = {
        enabled = 0, -- Don't fold individual list items
      },
    }

    -- Disable some features for better performance (optional)
    vim.g.vimtex_indent_enabled = 1
    vim.g.vimtex_syntax_enabled = 1

    vim.g.vimtex_syntax_conceal = {
      accents = 1,
      ligatures = 1,
      cites = 1,
      fancy = 1,
      spacing = 1,
      greek = 1,
      math_bounds = 1,
      math_delimiters = 1,
      math_fracs = 1,
      math_super_sub = 1,
      math_symbols = 1,
      sections = 0,
      styles = 1,
    }

    vim.opt.conceallevel = 2
  end,
}
