local M = {}

M.list = {}

local status_luasnip, ls = pcall(require, 'luasnip')
if (status_luasnip) then
	local s = ls.snippet
	local t = ls.text_node
	local i = ls.insert_node
	-- local c = ls.choice_node
	local fmt = require('luasnip.extras.fmt').fmt

	local javascript = {
		s('import', {
			t('import '),
			i(2, 'lib'),
			t(' from \''),
			i(1, 'lib'),
			t('\'')
		}),
		s('try', fmt(
			[[
				try {{
					{}
				}} catch (e) {{}}
			]],
			{
				i(1)
			}
		)),
		s('/**', fmt(
			[[
				/**
				 * {}
				 */
			]],
			{
				i(1)
			}
		)),
		s('const fn', {
			t('const '),
			i(1, 'fn'),
			t(' = '),
			i(2, 'async'),
			t(' ('),
			i(3),
			t(') => {'),
			i(4),
			t('}')
		})
	}

	local vue = {
		s('<script', {
			t('<script '),
			i(1, 'setup'),
			t(' lang="'),
			i(2, 'ts'),
			t('">'),
			i(3),
			t('</script>')
		}),
		s('<template', {
			t('<template'),
			i(1),
			t('>'),
			i(2),
			t('</template>')
		}),
		s('<style', {
			t('<style lang="'),
			i(1, 'sass'),
			t('">'),
			i(2),
			t('</style>')
		}),
		s('const props', {
			t('const props = defineProps<{'),
			i(1),
			t('}>()')
		}),
		s('const emit', {
			t('const emit = defineEmits<{ (e: \''),
			i(1, 'update:modelValue'),
			t('\', v: '),
			i(2, 'any'),
			t('): void }>()')
		}),
		s('onMounted', {
			t('onMounted(() => '),
			i(1, 'loadData()'),
			t(')')
		})
	}

	-- Add javascript in vue.
	for number, value in ipairs(javascript) do
		vue[6 + number] = value
	end

	M.list = {
		javascript = javascript,
		typescript = javascript,
		vue = vue
	}
end

return M
