function OnInit() {
    UltraEdit.processPIOnInit(`{
        "guid": "f393bd5b-5cae-424a-a8c0-b7f227e040b6",
        "ueplSurroundBraces": {
            "type": "Execute",
            "display name": "Surround with braces {}",
            "short description": "Simplify code wrapping with {}",
            "icon": "",
            "hotkey": "Ctrl + [",
            "chord": "Ctrl + C"
        },
        "ueplSurroundBrackets": {
            "type": "Execute",
            "display name": "Surround with brackets []",
            "short description": "Simplify code wrapping with []",
            "icon": "",
            "hotkey": "Ctrl + [",
            "chord": "Ctrl + B"
        },
        "ueplSurroundQuotes": {
            "type": "Execute",
            "display name": "Surround with quotes \\"\\"",
            "short description": "Simplify code wrapping with \\"\\"",
            "icon": "",
            "hotkey": "Ctrl + [",
            "chord": "Ctrl + Q"
        },
        "ueplSurroundParens": {
            "type": "Execute",
            "display name": "Surround with parentheses ()",
            "short description": "Simplify code wrapping with ()",
            "icon": "",
            "hotkey": "Ctrl + [",
            "chord": "Ctrl + P"
        },
        "ueplSurroundTags": {
            "type": "Execute",
            "display name": "Surround with tag markers <>",
            "short description": "Simplify code wrapping with <>",
            "icon": "",
            "hotkey": "Ctrl + [",
            "chord": "Ctrl + A"
        }
    }`);
}

/**
 * @def Function to surround code with {}
 * @desc this function will call SurroundCode fn, which has all the functionality
 */
function ueplSurroundBraces() {
    SurroundCode("{", "}");
}

/**
 * @def Function to surround code with []
 * @desc this function will call SurroundCode fn, which has all the functionality
 */
function ueplSurroundBrackets() {
    SurroundCode("[", "]");
}

/**
 * @def Function to surround code with ""
 * @desc this function will call SurroundCode fn, which has all the functionality
 */
function ueplSurroundQuotes() {
    SurroundCode("\"", "\"");
}

/**
 * @def Function to surround code with ()
 * @desc this function will call SurroundCode fn, which has all the functionality
 */
function ueplSurroundParens() {
    SurroundCode("(", ")");
}

/**
 * @def Function to surround code with <>
 * @desc this function will call SurroundCode fn, which has all the functionality
 */
function ueplSurroundTags() {
    SurroundCode("<", ">");
}

/**
 * Will replace selected text with given braces
 * @param {string} startBraces ' { | [ | " | ( | < '
 * @param {string} endBraces ' } | | | " | ) | > '
 */
function SurroundCode(startBraces, endBraces) {
    /* ------------------ Handel Error ------------------- */
    // Check if there are documents on editor and check if they are active
    // if not active show error and stop the process.
    if (UltraEdit.document.length < 1 || !UltraEdit.activeDocument.path) {
        handleError("Code Surround Plugin Error", "There are no files open.");
        return;
    };
    // exit processing if no text is selected
    if (!UltraEdit.activeDocument.isSel()) {
        handleError('Code Surround Plugin Error', 'No text selected');
        return;
    }

    /* ----------------- Process code surround ------------- */

    // Getting the seleced text
    var selText = UltraEdit.activeDocument.selection;
    UltraEdit.activeDocument.deleteText();
    var updatedText = `${startBraces}${selText}${endBraces}`;
    // Wriring the updated text to file
    UltraEdit.activeDocument.write(updatedText);

}

/**
 * Helper function to show formated error to a user.
 * It shows a dialog box and shows error in output window if provided
 * @param {string} title 
 * @param {string} titleDesc 
 * @param {string} outputText 
 */
function handleError(title, titleDesc, outputText = `Code Surround Plugin -> ${titleDesc}`) {
    UltraEdit.messageBox(titleDesc, title);
    UltraEdit.outputWindow.write(outputText);
}
