"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
// Tag-inserter/extension.ts
// Author: Szymon 'l7ssha' Uglis
const vscode = require("vscode");
function insertTag() {
    return __awaiter(this, void 0, void 0, function* () {
        const document_lang = vscode.window.activeTextEditor.document.languageId;
        if (document_lang != "html") {
            error("The file must be html file.");
            return;
        }
        const tag = yield vscode.window.showInputBox();
        if (tag == null && tag.trim() != "") {
            error("No empty tags permited!");
            return;
        }
        let selection = vscode.window.activeTextEditor.selection;
        if (!selection.isEmpty) {
            vscode.window.activeTextEditor.edit(builder => {
                builder.replace(selection, getInsertText(vscode.window.activeTextEditor.document.getText(selection), tag));
            });
        }
        else {
            error("Your selection is empty!");
            return;
        }
    });
}
exports.insertTag = insertTag;
;
// Some regex stuff.
function getInsertText(selection, tag) {
    const regexPattern = /(\w+).([A-Za-z])\w+=\"([^"]*)\"/;
    if (regexPattern.test(tag)) {
        const t = tag.split(" ", 1);
        return "<" + tag + ">" + selection + "</" + t[0] + ">";
    }
    else
        return "<" + tag + ">" + selection + "</" + tag + ">";
}
exports.getInsertText = getInsertText;
function error(text) {
    vscode.window.showErrorMessage(text);
}
//# sourceMappingURL=tagInserter.js.map