local M = {}

local supported_terminals = { "kitty", "ghostty" }

M.is_supported_terminal = function()
	for _, name in ipairs(supported_terminals) do
		if os.getenv("TERM"):find(name) then
			return true
		end
	end

	if os.getenv("TMUX") then
		return true
	end

	return false
end

-- check whether an external executable is available in $path.
--- @param cmd string   the program to look for.
--- @return boolean    when the command is found.
M.command_exits = function(cmd)
	if vim and vim.fn and vim.fn.executable then
		return vim.fn.executable(cmd) == 1
	end
	return false
end

local dependencies = {
	{
		command = "magick",
		message = "PDFReader DEPENDENCY MISING ERROR: 'magick' not found in $PATH. Please install ImageMagick.",
	},
	{
		command = "pdftotext",
		message = "PDFReader DEPENDENCY MISSING ERROR: 'pdftotext' not found in $PATH. Please install poppler-utils.",
	},
	{
		command = "pdfinfo",
		message = "PDFReader DEPENDENCY MISSING ERROR: 'pdfinfo' not found $PATH. Please install poppler-utils.",
	},
}

function M.check_depencencies()
	for _, dep in pairs(dependencies) do
		if not M.command_exits(dep.command) then
			vim.notify(dep.message, vim.log.levels.ERROR)
			return false
		end
	end
	return true
end

return M
