{# 
    editable_title - Make #title element editable.
    Parameters:
    - title: Page title
 #}
{% macro editable_title(title) -%}
    <form action="./" method="POST">
        <input type="hidden" class="csrf-token" name="csrf_token" value="{{ csrf_token() }}"/>
        <input type="text" autocomplete="off" spellcheck="false" id="newtitle" name="newtitle" value="{{ title }}" style="font-size: 1.5em; text-align: center; display: none;" />
        <div class="row center">
            <button type="submit" class="btn update" id="save" name="action" value="rename" style="display: none; width: 49.2%; margin: 3px;">{{ _("Update") }}</button>
            <button type="button" class="btn cancel" id="cancel" onclick="toggleEdit()" style="display: none; width: 49.2%; margin: 3px;">{{ _("Cancel") }}</button>
            <button type="button" class="btn edit" id="edit" onclick="toggleEdit()">{{ _("Edit Name") }}</button>
        </div>
        <br>
    </form>

    <script>
	    function toggleEdit() {
            var title = document.getElementById("title");
            var newtitle = document.getElementById("newtitle");
            var edit = document.getElementById("edit");
            var cancel = document.getElementById("cancel");
            var save = document.getElementById("save");

            if (edit.style.display === 'none'){
                edit.style.display = 'block';
                cancel.style.display = 'none';
                save.style.display = 'none';
                title.style.display = 'block';
                newtitle.style.display = 'none';
            } else {
                newtitle.style.fontSize = '1.5em';
                newtitle.value = '{{ title.replace("'","\\'") }}';
                newtitle.style.display = 'block';
                edit.style.display = 'none';
                cancel.style.display = 'inline-block';
                save.style.display = 'inline-block';
                title.style.display = 'none';
            }
        }
    </script>
{%- endmacro %}