<!DOCTYPE html>
<html lang="en">
<head>
    <title>GohCMS | Post edition</title>
    {{.Head}}
</head>
<body class="text-dark vh-100 d-flex flex-column">
{{.Navbar}}
<div class="container mt-3 text-black-50 d-flex flex-column h-100">
    <div class="d-flex align-items-center justify-content-between">
        <div>
            <h1>Post - edition</h1>
            <label for="postContent">Edition</label>
        </div>
        <div class="d-flex justify-content-center align-items-center">
            <button class="btn btn-success d-flex justify-content-center align-items-center gap-1" style="fill: white;">
                <svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M840-680v480q0 33-23.5 56.5T760-120H200q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h480l160 160Zm-80 34L646-760H200v560h560v-446ZM480-240q50 0 85-35t35-85q0-50-35-85t-85-35q-50 0-85 35t-35 85q0 50 35 85t85 35ZM240-560h360v-160H240v160Zm-40-86v446-560 114Z"/></svg>
                Save
            </button>
        </div>
    </div>
    <div class="text-black-50 d-flex align-items-center justify-content-center h-100 py-3">
        <textarea id="postContent" name="postContent"></textarea>
    </div>
</div>

<script src="/static/tinymce/js/tinymce/tinymce.min.js"></script>
<script>
    tinymce.init({
        selector: '#postContent',
        promotion: false,
        plugins: 'image',
        width: '100%',
        height: '100%',
        images_upload_handler: (blobInfo, progress) => new Promise((resolve, reject) => {
            // const xhr = new XMLHttpRequest();
            // xhr.withCredentials = false;
            // xhr.open('POST', 'postAcceptor.php');
            //
            // xhr.upload.onprogress = (e) => {
            //     progress(e.loaded / e.total * 100);
            // };
            //
            // xhr.onload = () => {
            //     if (xhr.status === 403) {
            //         reject({message: 'HTTP Error: ' + xhr.status, remove: true});
            //         return;
            //     }
            //
            //     if (xhr.status < 200 || xhr.status >= 300) {
            //         reject('HTTP Error: ' + xhr.status);
            //         return;
            //     }
            //
            //     const json = JSON.parse(xhr.responseText);
            //
            //     if (!json || typeof json.location != 'string') {
            //         reject('Invalid JSON: ' + xhr.responseText);
            //         return;
            //     }
            //
            //     resolve(json.location);
            // };
            //
            // xhr.onerror = () => {
            //     reject('Image upload failed due to a XHR Transport error. Code: ' + xhr.status);
            // };
            //
            // const formData = new FormData();
            // formData.append('file', blobInfo.blob(), blobInfo.filename());
            //
            // xhr.send(formData);
        }),
    })
</script>
</body>
</html>
