var TypeScript = require("./typescript/tss");

var f = require("./src/formatter");
var s = require("./src/syntaxTree");
var c = require("./src/compiler");

(function () {
    var formatCodeOptions = f.createDefaultFormatCodeOptions();
    formatCodeOptions.ConvertTabsToSpaces = false;
    formatCodeOptions.NewLineCharacter = "\n";
    formatCodeOptions.PlaceOpenBraceOnNewLineForControlBlocks = true;
    formatCodeOptions.InsertSpaceAfterFunctionKeywordForAnonymousFunctions = true;

    var content = "/// <reference path=\"./test.ts\" />\n class Sample{\n                   hello     (word ='world'){return       'Hello, '+word;}\n}";

    var result = f.applyFormatterToContent(content, formatCodeOptions);

    console.log(result);
})();

(function () {
    var content = "/// <reference path=\"./test.ts\" />\n class Sample{\n                   hello     (word ='world'){return       'Hello, '+word;}\n}";

    var ast = s.getAstByContent(content);
    var astWalkerFactory = TypeScript.getAstWalkerFactory();
    astWalkerFactory.simpleWalk(ast, function (ast, state) {
        console.log(TypeScript.SyntaxKind[ast.kind()]);
    });

    var replacer = function (key, value) {
        if (key !== "parent") {
            return value;
        } else {
            return null;
        }
    };
    console.log(JSON.stringify(ast, replacer, 2));
})();

(function () {
    var content = "class Sample{\n                   hello     (word ='world'){return       'Hello, '+word;}\n}";
    var settings = c.createCompilationSettings();
    settings.codeGenTarget = 1 /* EcmaScript5 */;
    settings.moduleGenTarget = 1 /* Synchronous */;

    var iter = c.compileWithContent(content, settings);
    while (iter.moveNext()) {
        var result = iter.current();
        result.diagnostics.forEach(function (d) {
            var info = d.info();
            if (info.category === 1 /* Error */) {
                console.error(d.message());
            } else {
                console.log(d.message());
            }
        });
        result.outputFiles.forEach(function (outFile) {
            console.log(outFile.name, outFile.text);
        });
    }
})();
