<?php

	enum Snippet: string {
		// Path relative from root
		private const REL_BASE_PATH = "modules/snippet/snippets/";

		// Languages
		case JAVASCRIPT = ".js";
		case CSS        = ".css";
		case PLAINTEXT  = ".txt";
		case PHP        = ".php";

		public static function put(string $name, self $lang): string {
				// Create path relative from base with filename and language extension (from enum value)
				$path = VV::root(self::REL_BASE_PATH . $name . $lang->value);

				// Bail out if snippet can't be found
				if (!is_file($path)) {
						return "<pre><code class='language-plaintext'>!REF#</code></pre>";
				}

				// Use enum name in lowercase as highlight.js lanuage definer
				$output = "<pre><code class='language-" . strtolower($lang->name) . "'>";
				$output .= htmlspecialchars(file_get_contents($path));
				$output .= "</code></pre>";

				return $output;
		}
	}

?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.10.0/styles/github-dark.min.css"/>
<script type="module"><?= VV::js("modules/snippet/snippet.js") ?></script>