{% extends "layout-semantic2.html.twig" %}
{% block csslocal %}
    <link rel="stylesheet" href="/css/simplemde.min.css">
{% endblock %}
{% block middle %}
    <div class="ui segment">
        <textarea id="text"></textarea>
    </div>
    <div class="ui segment">
        <button class="ui primary basic button" onclick="saveChanges()">Save article</button>
    </div>
{% endblock %}
{% block jslocal %}
    <script src="/js/simplemde/simplemde.min.js"></script>
    <script>
        var simplemde;
        simplemde = new SimpleMDE({
            initialValue: '{{ revision.Text }}',
            hideIcons: ['guide', 'side-by-side', 'link', 'image', 'horizontal-rule'],
            showIcons: ['bold', 'italic', 'heading', 'heading-smaller', 'heading-bigger',
                'heading-1', 'heading-2', 'heading-3', 'code', 'quote', 'unordered-list', 'ordered-list',
                'clean-block', 'table', 'preview'],
            spellChecker: false
        });

        function saveChanges() {
            var payload = {
                action: "create",
                termName: window.location.pathname,
                text: simplemde.value()
            };

            var xhr = $.post(window.location.pathname, payload);
            xhr.done(function (data) {
                console.log(data);
                //window.location.href= '/wiki/';
            })
        }
    </script>
{% endblock %}