local ls = require("luasnip")
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node
local fmt = require("luasnip.extras.fmt").fmt

ls.add_snippets("tex", {

  -- \beg → full figure environment
  s(
    "beg",
    fmt(
      [[
\begin{{{}}}{}
{}
\end{{{}}}]],
      {
        i(1, "environment"),
        i(2, ""),
        i(3, ""),
        -- mirror node 1 so \end matches \begin automatically
        require("luasnip.extras").rep(1),
      }
    )
  ),

  -- fig → full figure block
  s(
    "fig",
    fmt(
      [[
\begin{{figure}}[htbp]
    \centering
    \includegraphics[width={}]{{{}}
    \caption{{{}}}
    \label{{fig:{}}}
\end{{figure}}]],
      {
        i(1, "0.8\\textwidth"),
        i(2, "file"),
        i(3, "caption"),
        i(4, "label"),
      }
    )
  ),

  -- eq → equation
  s(
    "eq",
    fmt(
      [[
\begin{{equation}}
    {}
\end{{equation}}]],
      { i(1, "") }
    )
  ),

  -- ali → align
  s(
    "ali",
    fmt(
      [[
\begin{{align}}
    {} &= {} \\
\end{{align}}]],
      { i(1, ""), i(2, "") }
    )
  ),
})
