﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
	<style type="text/css">
		:root {
			--url: url("");
		}

		html,
		body {
                        border-top-left-radius: 10px; /* Top left rounded corner */
                        border-bottom-left-radius: 10px;
			background-color: #050505;
			width: 100%;
			height: 100%;
			margin: 0;
			padding: 0;
			overflow: hidden;
			font-family: consolas, 'poppins', monospace;
			color: white;
		}

		.margin:first-child {
			background-image: var(--url);
			background-size: cover;
			background-repeat: no-repeat;
			background-attachment: fixed;
		}

		.lines-content:nth-of-type(1),
		.monaco-editor-background:nth-of-type(1) {
			background-image: var(--url);
			background-size: cover;
			background-repeat: no-repeat;
			background-attachment: fixed;
		}
	</style>
	<meta charset="utf-8" />
	<title></title>
</head>

<body>
	<div id="container" style="width:100%;height:100%;"></div>
	<script src="vs/loader.js"></script>
	<script type="text/javascript">
		require.config({
			paths: {
				'vs': 'vs',
			}
		});

		var GetText;
		var SetText;
		var SetTheme;
		var SetScroll;
		var ShowError;
		var Refresh;

		var SwitchMinimap;
		var SwitchReadonly;
		var SwitchRenderWhitespace;
		var SwitchLinks;
		var SwitchLineHeight;
		var SwitchFontSize;
		var SwitchFolding;
		var SwitchAutoIndent;
		var SwitchFontFamily;
		var SwitchFontLigatures;
		var AddIntellisense;

		var editor;
		var Proposals = [];

		require(['vs/editor/editor.main'], function () {
			function getDependencyProposals() {
				let newProposals = [];
				for (let index = 0; index < Proposals.length; index++) {
					const element = Proposals[index];
					let newElement = {}
					for (const key in element) {
						if (key == "__children__") {
							continue;
						};
						newElement[key] = element[key];
					}
					newProposals.push(newElement)
				}
				return newProposals;
			}

			monaco.editor.defineTheme('Dark', {
                base: 'vs-dark',
                inherit: true,
 			rules: [
	{ "token": "variable.language.self", "foreground": "ffffff" },
        { "token": "variable.parameter.variadic", "foreground": "ffffff" },
        { "token": "variable.parameter.function", "foreground": "a9c4f5" },
        { "token": "variable.other.constant", "foreground": "ffffff" },
        { "token": "variable.property", "foreground": "ffffff" },
        { "token": "variable.object.property", "foreground": "ffffff" },
        { "token": "keyword", "foreground": "6495ed" },
        { "token": "keyword.local", "foreground": "6495ed", "fontStyle": "bold" },
        { "token": "keyword.operator", "foreground": "6495ed" },
        { "token": "keyword.operator.type.annotation", "foreground": "6495ed" },
        { "token": "keyword.operator.typedef.annotation", "foreground": "6495ed" },
        { "token": "keyword.control.export", "foreground": "6495ed", "fontStyle": "bold" },
        { "token": "operator", "foreground": "ffffff" },
        { "token": "operator.type", "foreground": "ffffff" },
        { "token": "operator.special", "foreground": "ffffff" },
        { "token": "entity.name.type.alias", "foreground": "ffffff" },
        { "token": "entity.name.function", "foreground": "c0c0c0" },
        { "token": "global", "foreground": "1f66e5", "fontStyle": "bold" },
        { "token": "storage.type", "foreground": "ffffff" },
        { "token": "comment", "foreground": "999999", "fontStyle": "italic" },
        { "token": "comment.highlight.title", "foreground": "999999", "fontStyle": "italic" },
        { "token": "comment.highlight.name", "foreground": "999999", "fontStyle": "italic" },
        { "token": "comment.delimiter.modifier", "foreground": "999999", "fontStyle": "italic" },
        { "token": "comment.highlight.modifier", "foreground": "999999", "fontStyle": "italic" },
        { "token": "comment.highlight.descriptor", "foreground": "999999", "fontStyle": "italic" },
        { "token": "delimiter.longstring", "foreground": "ffffff" },
        { "token": "delimiter.bracket", "foreground": "ffffff" },
        { "token": "delimiter.array", "foreground": "ffffff" },
        { "token": "delimiter.parenthesis", "foreground": "ffffff" },
        { "token": "delimiter", "foreground": "ffffff" },
        { "token": "string", "foreground": "a9c4f5" },
        { "token": "longstring", "foreground": "a9c4f5" },
        { "token": "string.delimeter", "foreground": "a9c4f5" },
        { "token": "string.escape", "foreground": "a9c4f5" },
        { "token": "punctuation.separator.arguments", "foreground": "ffffff" },
        { "token": "punctuation.separator.parameter", "foreground": "ffffff" },
        { "token": "punctuation.separator.table", "foreground": "ffffff" },
        { "token": "punctuation.definition.block", "foreground": "ffffff" },
        { "token": "punctuation.definition.parameters", "foreground": "ffffff" },
        { "token": "punctuation.definition.typeparameters", "foreground": "ffffff" },
        { "token": "constant.language", "foreground": "a092f3" },
        { "token": "number", "foreground": "f08080" },
        { "token": "constants", "foreground": "ffffff" },
        { "token": "support.function", "foreground": "a092f3" },
        { "token": "support.function.library", "foreground": "ffffff" },
        { "token": "support.type", "foreground": "ffffff" },
                	],
                colors: {
		    'editor.background': '#050505',
                    'minimap.background': '#0d0d0f'
                }
            });

			require(['vs/basic-languages/monaco.contribution'], function () {
				monaco.languages.registerCompletionItemProvider('lua', {
					provideCompletionItems: function (model, position) {
						return {
							suggestions: getDependencyProposals(),
						};
					},
					triggerCharacters: ['.', ':', '"'],
				});

				editor = monaco.editor.create(document.getElementById('container'), {
					value: '',
					language: 'lua',
					theme: "Dark",
					folding: true,
					dragAndDrop: true,
					links: true,
					minimap: {
						enabled: false,
					},
					showFoldingControls: "always",
					smoothScrolling: true,
					stopRenderingLineAfter: 6500,
					fontSize: 14,
					cursorBlinking: "smooth",
					cursorSmoothCaretAnimation: true,
					foldingHighlight: true,
					fontLigatures: true,
					formatOnPaste: true,
					showDeprecated: true,
					suggest: {
						snippetsPreventQuickSuggestions: true,
					},
				});

				editor.getModel().updateOptions({ insertSpaces: true })
			});

			window.onresize = function () {
				editor.layout();
			}

			Cut = function() {
				editor.focus();
				document.execCommand('cut');
			}

			Copy = function() {
				editor.focus();
				document.execCommand('copy');
			}

			Paste = function() {
				editor.focus();
				document.execCommand('paste');
			}

			Undo = function() {
				editor.focus();
				document.execCommand('undo');
			}

			Redo = function() {
				editor.focus();
				document.execCommand('redo');
			}

			Delete = function() {
				editor.focus();
				document.execCommand('delete');
			}

			SelectAll = function() {
				editor.focus();
				document.execCommand('selectAll');
			}

			GetText = function() {
				return editor.getValue();
			}

			SetText = function(x) {
				editor.setValue(x);
			}

			GetProposals = function () {
				return Proposals;
			}


			OnDidChangeContent = function (callback) {
				return editor.onDidChangeModelContent((event) => {
					callback(editor.getValue());
				});
			}

			OnDidChangeCursorPosition = function (callback) {
				return editor.onDidChangeCursorPosition((event) => {
					callback(event.position);
				});
			}

			SetTheme = function (themeName) {
				if (themeName == 'Dark') {
					monaco.editor.setTheme('Dark')
				}
			}

			SwitchMinimap = function (flag) {
				editor.updateOptions({
					minimap: {
						enabled: true,
					}
				});
			}

			SwitchReadonly = function (flag) {
				editor.updateOptions({
					readOnly: flag,
				});
			}

			SwitchRenderWhitespace = function (op) {
				editor.updateOptions({
					renderWhitespace: op,
				});
			}

			SwitchLinks = function (flag) {
				editor.updateOptions({
					links: flag,
				});
			}

			SwitchLineHeight = function (num) {
				editor.updateOptions({
					lineHeight: num,
				});
			}

			SwitchFontSize = function (num) {
				editor.updateOptions({
					fontSize: num,
				});
			}

			SwitchFolding = function (flag) {
				editor.updateOptions({
					folding: flag,
				});
			}

			SwitchAutoIndent = function (flag) {
				editor.updateOptions({
					autoIndent: flag,
				});
			}

			SwitchFontFamily = function (name) {
				editor.updateOptions({
					fontFamily: name,
				});
			}

			SwitchFontLigatures = function (flag) {
				editor.updateOptions({
					fontLigatures: flag,
				});
			}

			ShowError = function (line, column, endline, endcolumn, errMessage) {
				editor.revealPositionInCenter({ lineNumber: line, column: column });
				editor.deltaDecorations([], [
					{
						range: new monaco.Range(line, column, endline, endcolumn),
						options: {
							inlineClassName: 'squiggly-error',
							hoverMessage: {
								value: errMessage,
							}
						},
					},
				]);
			}

			AddSnippet = function (kindName, snippetName, data) {
				let snippet = {
					insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
					kind: monaco.languages.CompletionItemKind[kindName],
				};
				for (const key in data) {
					let value = data[key];
					if (key == "insertText" && typeof value == "object") {
						value = value.join("\n");
					};
					snippet[key] = value;
				}
				if (!snippet.label) {
					snippet.label = snippetName
				}
				if (!snippet.insertText) {
					snippet.insertText = snippetName
				}
				Proposals.push(snippet);
			}

			AddRawSnippet = function (data) {
				Proposals.push(data);
			}

			SetScroll = function (line) {
				editor.revealLineInCenter({ lineNumber: line });
			}

			Refresh = function () {
				var Text = GetText();
				SetText(Text);
				editor.trigger('keyboard', 'type', { text: Text });
			}

		AddIntellisense = function(l, k, d, i) {
                    console.log(l);
                    console.log(k);
                    console.log(d);
                    console.log(i);
                    var t;
                    switch(k)
                    {
                        case "Class":
                            t = monaco.languages.CompletionItemKind.Class;
                            break;
                        case "Color":
                            t = monaco.languages.CompletionItemKind.Color;
                            break;
                        case "Constructor":
                            t = monaco.languages.CompletionItemKind.Constructor;
                            break;
                        case "Enum":
                            t = monaco.languages.CompletionItemKind.Enum;
                            break;
                        case "Field":
                            t = monaco.languages.CompletionItemKind.Field;
                            break;
                        case "File":
                            t = monaco.languages.CompletionItemKind.File;
                            break;
                        case "Folder":
                            t = monaco.languages.CompletionItemKind.Folder;
                            break;
                        case "Function":
                            t = monaco.languages.CompletionItemKind.Function;
                            break;
                        case "Interface":
                            t = monaco.languages.CompletionItemKind.Interface;
                            break;
                        case "Keyword":
                            t = monaco.languages.CompletionItemKind.Keyword;
                            break;
                        case "Method":
                            t = monaco.languages.CompletionItemKind.Method;
                            break;
                        case "Module":
                            t = monaco.languages.CompletionItemKind.Module;
                            break;
                        case "Property":
                            t = monaco.languages.CompletionItemKind.Property;
                            break;
                        case "Reference":
                            t = monaco.languages.CompletionItemKind.Reference;
                            break;
                        case "Snippet":
                            t = monaco.languages.CompletionItemKind.Snippet;
                            break;
                        case "Text":
                            t = monaco.languages.CompletionItemKind.Text;
                            break;
                        case "Unit":
                            t = monaco.languages.CompletionItemKind.Unit;
                            break;
                        case "Value":
                            t = monaco.languages.CompletionItemKind.Value;
                            break;
                        case "Variable":
                            t = monaco.languages.CompletionItemKind.Variable;
                            break;
                    }
                    
                    Proposals.push({
                        label: l,
                        kind: t,
                        detail: d,
                        insertText: i
                    });

                    console.log(Proposals);
                }
		});
	</script>
</body>

</html>