-- Lua snippets
local ls = require("luasnip")
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
local c = ls.choice_node
local d = ls.dynamic_node
local sn = ls.snippet_node
local fmt = require("luasnip.extras.fmt").fmt
local rep = require("luasnip.extras").rep

-- Return a table of snippets for Lua
-- stylua: ignore start
return {
  -- Basic print statement
  s("pr", {
    t('print("'),
    i(1, "text"),
    t('")'),
  }),

  -- Function definition
  s("fn", fmt([[
  local function {}({})
    {}
  end
  ]], {
    i(1, "name"),
    i(2, ""),
    i(3, "-- TODO: implement"),
  })),

  -- Module pattern
  s("mod", fmt([[
  local {} = {{}}

  function {}:new(o)
    o = o or {{}}
    setmetatable(o, self)
    self.__index = self
    return o
  end

  {}

  return {}
  ]], {
    i(1, "ModuleName"),
    rep(1),
    i(2, "-- TODO: add methods"),
    rep(1),
  })),

  -- For loop
  s("for", fmt([[
  for {} = {}, {} do
    {}
  end
  ]], {
    i(1, "i"),
    i(2, "1"),
    i(3, "10"),
    i(4, "-- TODO: loop body"),
  })),

  -- For pairs loop
  s("forp", fmt([[
  for {}, {} in pairs({}) do
    {}
  end
  ]], {
    i(1, "k"),
    i(2, "v"),
    i(3, "table"),
    i(4, "-- TODO: loop body"),
  })),
}
-- stylua: ignore end
