local md_like = {
	"markdown",
	"pandoc",
	"quarto",
	"vimwiki",
}
local org_like = {
	"norg",
	"org",
}
local prose_ft = {
	unpack(md_like),
	unpack(org_like),
	"asciidoc",
	"bib",
	"context",
	"gitcommit",
	"latex",
	"mail",
	"rst",
	"tex",
	"text",
	"typst",
	"rmd",
}

local prose_plugs = {
	-- UI improvements
	-- provide distraction free writing
	{
		"folke/zen-mode.nvim",
		config = true,
		cmd = { "ZenMode" },
		dependencies = { "folke/twilight.nvim" },
		keys = { { "<leader>sz", ":ZenMode<cr>", silent = true, desc = "toggle zen mode" } },
	},
	{
		"andrewferrier/wrapping.nvim",
		opts = {
			create_keymaps = false,
			notify_on_switch = false,
			-- softener = { quarto = true, markdown = true, text = true, asciidoc = true },
			auto_set_mode_filetype_allowlist = prose_ft,
		},
		-- event = { "BufReadPre", "BufNewFile" },
		ft = prose_ft,
		keys = {
			{
				"[ow",
				function()
					require("wrapping").soft_wrap_mode()
				end,
				silent = true,
				desc = "soft wrap",
			},
			{
				"]ow",
				function()
					require("wrapping").hard_wrap_mode()
				end,
				silent = true,
				desc = "hard wrap",
			},
		},
	},
	-- displays prettier md rendering
	{
		"MeanderingProgrammer/render-markdown.nvim",
		main = "render-markdown",
		opts = {
			file_types = { unpack(md_like) },
			render_modes = { "n", "c", "i" },
			code = {
				sign = false,
				width = "block",
				right_pad = 1,
			},
			checkbox = {
				custom = {
					todo = { raw = "[-]", rendered = "󰡖 ", highlight = "RenderMarkdownTodo" },
					removed = { raw = "[_]", rendered = "󱋭 ", highlight = "RenderMarkdownTodo" },
				},
			},
		},
		name = "render-markdown", -- Only needed if you have another plugin named markdown.nvim
		dependencies = {
			"nvim-treesitter/nvim-treesitter",
			"nvim-tree/nvim-web-devicons",
		},
		ft = md_like,
		cmd = "RenderMarkdown",
		keys = {
			{
				"<leader>pp",
				function()
					require("render-markdown").toggle()
				end,
				silent = true,
				desc = "toggle md rendering",
			},
		},
	},
	-- generate an auto-updating html preview for md files
	-- uses the very nice peek if deno is available, otherwise falls back to markdown-preview
	{
		"toppair/peek.nvim",
		event = { "VeryLazy" },
		cond = vim.fn.executable("deno") == 1,
		build = "deno task --quiet build:fast",
		ft = md_like,
		config = function()
			require("peek").setup()
			vim.api.nvim_create_user_command("PeekOpen", require("peek").open, {})
			vim.api.nvim_create_user_command("PeekClose", require("peek").close, {})
		end,
	},
	{
		"iamcco/markdown-preview.nvim",
		event = { "VeryLazy" },
		cond = vim.fn.executable("deno") == 0,
		build = function()
			vim.fn["mkdp#util#install"]()
		end,
		ft = md_like,
	},

	-- easy copy paste of images into markup files
	{
		"HakonHarnes/img-clip.nvim",
		event = "VeryLazy",
		opts = {
			filetypes = {
				quarto = {
					url_encode_path = true,
					template = "![$CURSOR]($FILE_PATH)",
					download_images = false,
				},
			},
		},
		cmd = { "PasteImage" },
		keys = {
			{ "<leader>pi", "<cmd>PasteImage<cr>", desc = "Paste image from system clipboard" },
		},
		ft = prose_ft,
	},

	-- bring zettelkasten commands
	{
		"mickael-menu/zk-nvim",
		config = function()
			if require("core.util").is_available("which-key") then
				require("which-key").add({
					{ "<leader>n", group = "notes" },
					{ "<localleader>n", group = "note" },
					{ "<localleader>n", group = "note", mode = "v" },
				})

				require("zk.commands").add("ZkOrphans", function(opts)
					opts = vim.tbl_extend("force", { orphan = true }, opts or {})
					require("zk").edit(opts, { title = "Zk Orphans" })
				end)
			end
			require("zk").setup({
				picker = "telescope",
				lsp = {
					auto_attach = {
						enabled = true,
						filteypes = { "markdown", "quarto" },
					},
				},
			})
		end,
		ft = prose_ft,
		cmd = {
			"ZkBacklinks",
			"ZkCd",
			"ZkIndex",
			"ZkInsertLink",
			"ZkInsertLinkAtSelection",
			"ZkLinks",
			"ZkMatch",
			"ZkNew",
			"ZkNewFromContentSelection",
			"ZkNewFromTitleSelection",
			"ZkNotes",
			"ZkTags",
			"ZkOrphans",
		},
		keys = {
			-- additional key instpirations https://github.com/al1-ce/MonolithVim/blob/master/after/ftplugin/markdown.lua
			{ "<leader>ni", "<cmd>edit ~/documents/notes/index.md<cr>", desc = "open index", silent = true },
			{ "<leader>nn", "<cmd>ZkNew { title = vim.fn.input('Title: ') }<cr>", desc = "new note" },
			{ "<leader>nn", ":'<,'>ZkNewFromTitleSelection<cr>", desc = "new note from selection", mode = "v" },
			{ "<leader>nN", ":'<,'>ZkNewFromContentSelection<cr>", desc = "content from selection", mode = "v" },
			{ "<leader>nl", "<cmd>ZkNotes { sort = { 'modified' } }<cr>", desc = "note list" },
			{
				"<leader>nf",
				"<Cmd>ZkNotes { sort = { 'modified' }, match = { vim.fn.input('Search: ') } }<CR>",
				desc = "note search",
			},
			{ "<leader>nf", "<cmd>ZkMatch<cr>", desc = "find note from selection", mode = "v" },
			{ "<leader>nt", "<cmd>ZkTags<cr>", desc = "note tags" },
			{ "<leader>nc", "<cmd>ZkCd<cr>", desc = "notedir cd" },
			{ "<leader>no", "<cmd>ZkOrphans { sort = { 'modified' } }<cr>", desc = "orphans list" },
			{ "<localleader>nb", "<cmd>ZkBacklinks<cr>", desc = "note backlinks" },
			{ "<localleader>nl", "<cmd>ZkLinks<cr>", desc = "note links" },
		},
	},

	-- syntax highlighting for markdown criticmarkup (comments, additions, ...)
	{ "vim-pandoc/vim-criticmarkup", ft = md_like },

	-- create mindmaps from your markdown
	{
		"Zeioth/markmap.nvim",
		cmd = { "MarkmapOpen", "MarkmapSave", "MarkmapWatch", "MarkmapWatchStop" },
		config = true,
	},

	-- cite as you write from papis databases
	-- ADDITIONAL DEPENDENCIES: papis and yq in shell env
	-- {
	-- 	"jghauser/papis.nvim",
	-- 	dependencies = {
	-- 		"kkharji/sqlite.lua",
	-- 		"MunifTanjim/nui.nvim",
	-- 		"pysan3/pathlib.nvim",
	-- 		"nvim-neotest/nvim-nio",
	-- 		"nvim-treesitter/nvim-treesitter",
	-- 	},
	-- 	cond = vim.fn.executable("papis") == 1 and vim.fn.executable("yq") == 1,
	-- 	ft = writing_ft,
	-- 	lazy = false,
	-- 	config = function()
	-- 		require("papis").setup({})
	-- 	end,
	-- },
	{
		"barreiroleo/ltex_extra.nvim",
		branch = "dev",
	},
	{ "let-def/texpresso.vim", ft = { "tex" } },
}

return prose_plugs
