/*globals _:false */
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const ace_js_1 = tslib_1.__importDefault(require("./ace/ace.js"));
const canvas_1 = require("./canvas");
require('./ace/mode-prisma.js');
require('./ace/theme-twilight.js');
// import datamodel from '../public/datamodel.json';
window.addEventListener("load", async function () {
    // Your code to run since DOM is loaded and ready
    let generateButton = document.getElementById('generate');
    const schema = await (await fetch('/public/schema.prisma')).text();
    const datamodel = await (await fetch('/generate', { method: "POST", body: schema, })).json();
    let canvas = new canvas_1.Canvas("canvas", datamodel);
    var editor = ace_js_1.default.edit("editor");
    editor.setTheme("ace/theme/twilight");
    editor.setValue(schema);
    var PrismaMode = ace_js_1.default.require("ace/mode/prisma").Mode;
    editor.session.setMode(new PrismaMode());
    generateButton && generateButton.addEventListener('click', async () => {
        const datamodel = await (await fetch('/generate', { method: "POST", body: editor.getValue(), })).json();
        canvas.updateDatamodel(datamodel);
    });
}, false);
