<?php

declare(strict_types=1);

/** @var bool $blogCanManage */
/** @var bool $compose */
/** @var bool $editMode */
/** @var string $csrf */

require_once dirname(__DIR__, 3) . '/includes/fate_rich_editor.php';

$blogNeedEditor = !empty($blogCanManage) && (!empty($compose) || !empty($editMode));
if ($blogNeedEditor) {
    fate_rich_editor_foot_assets('api/blog_upload.php', $csrf);
    if (!empty($compose) || !empty($editMode)) {
        ?>
        <script>
        document.addEventListener('DOMContentLoaded', function () {
            var editorIds = ['blog-body', 'blog-edit-body', 'blog-list-edit-body'];
            if (typeof window.jQuery === 'undefined' || !window.jQuery.fn.summernote) {
                return;
            }
            for (var i = 0; i < editorIds.length; i++) {
                var ta = document.getElementById(editorIds[i]);
                if (ta) {
                    window.jQuery(ta).trigger('focus');
                    break;
                }
            }
        });
        </script>
        <?php
    }
}
