<?php
namespace NeoMotionBeta\NeoDraw; if (!defined("ABSPATH")) { die("neoWP direct access not allowed"); }






\NeoMotionBeta\NeoGlobal\add_action_hook("neo_init", function () {
    \NeoMotionBeta\NeoGlobal\enqueue_js_variable_backend_and_frontend("neoDrawEditorUrl", \NeoMotionBeta\NeoGlobal\get_backend_page_url("neo-draw--editor"));
});


\NeoMotionBeta\NeoGlobal\register_backend_page("neo-draw--editor", fn () => \NeoMotionBeta\NeoGlobal\current_user_can__neo_draw(), function () {
    
    \NeoMotionBeta\NeoGlobal\enqueue_js_variable_backend("neoDrawEditorDbEntriesUsageUrl",   \NeoMotionBeta\NeoGlobal\get_db_entries_page_url());
    $neo_draw_editor_locale_parts = explode("_", get_locale());
    $neo_draw_editor_language_code = isset($neo_draw_editor_locale_parts[1]) ? strtolower($neo_draw_editor_locale_parts[0]) . "-" . strtoupper($neo_draw_editor_locale_parts[1]) : strtolower($neo_draw_editor_locale_parts[0]);
    \NeoMotionBeta\NeoGlobal\enqueue_js_variable_backend("neoDrawEditorLanguageCode",        $neo_draw_editor_language_code);
    \NeoMotionBeta\NeoGlobal\enqueue_js_variable_backend("neoDrawEditorIconLibraryUrl",      \NeoMotionBeta\NeoGlobal\get_backend_page_url("neo-draw--icon-library"));
    [$neo_draw_settings_section_url, $interface_ok] = \NeoMotionBeta\NeoGlobal\call_interface_func_implemented('\NeoMotionBeta\NeoSettings\interface_get_neo_settings_section_url_20260613')("neo-draw"); if (!$interface_ok) { $neo_draw_settings_section_url = ""; }
    \NeoMotionBeta\NeoGlobal\enqueue_js_variable_backend("neoDrawEditorSettingsPageUrl",     $neo_draw_settings_section_url);
    \NeoMotionBeta\NeoGlobal\enqueue_js_variable_backend("neoDrawEditorWpSiteUrl",           get_site_url());
    \NeoMotionBeta\NeoGlobal\enqueue_js_variable_backend("neoDrawEditorPluginVersion",       \NeoMotionBeta\NeoGlobal\plugin_version());
    [$neo_animate_editor_head_code, $neo_animate_interface_ok] = \NeoMotionBeta\NeoGlobal\call_interface_func_implemented('\NeoMotionBeta\NeoAnimate\interface_get_neo_draw_editor_head_html_20260611')();
    [$neo_motion_editor_head_code, $neo_motion_interface_ok]   = \NeoMotionBeta\NeoGlobal\call_interface_func_implemented('\NeoMotionBeta\NeoMotion\interface_get_neo_draw_editor_head_html_20260615')();
    [$neo_animate_web_component_importer_url, $neo_animate_web_component_importer_interface_ok] = \NeoMotionBeta\NeoGlobal\call_interface_func_implemented('\NeoMotionBeta\NeoAnimate\interface_get_neo_draw_editor_web_component_importer_url_20260615')();
    [$neo_motion_web_component_importer_url,  $neo_motion_web_component_importer_interface_ok]  = \NeoMotionBeta\NeoGlobal\call_interface_func_implemented('\NeoMotionBeta\NeoMotion\interface_get_neo_draw_editor_web_component_importer_url_20260615')();
    \NeoMotionBeta\NeoGlobal\enqueue_js_variable_backend("neoDrawAnimationIntegrationAvailable", $neo_animate_interface_ok);
    \NeoMotionBeta\NeoGlobal\enqueue_js_variable_backend("neoDrawMotionIntegrationAvailable",    $neo_motion_interface_ok);
    
    ?><!DOCTYPE html>
    <html>
        <head>
            <title>neoDraw Editor</title>
            <meta charset="UTF-8" />
            <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover, shrink-to-fit=no">
            <script>

                window.EXCALIDRAW_ASSET_PATH = "<?php echo esc_url(\NeoMotionBeta\NeoGlobal\plugin_url()) ?>/neo-draw--excalidraw-thirdparty/";
            </script>

            <script>
                <?php echo \NeoMotionBeta\NeoGlobal\get_code_for_js_variables("backend") /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ ?>; /* Output is properly escaped in get_code_for_js_variables() for security */
            </script>
            <?php if ($neo_animate_interface_ok) { ?><script>
                <?php echo $neo_animate_editor_head_code /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ ?>; /* Output is properly escaped in get_code_for_js_variables() for security */
            </script><?php } ?>
            <?php if ($neo_motion_interface_ok) { ?><script>
                <?php echo $neo_motion_editor_head_code /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped */ ?>; /* Output is properly escaped in get_code_for_js_variables() for security */
            </script><?php } ?>

            <link rel="stylesheet" href="<?php echo esc_url(\NeoMotionBeta\NeoGlobal\plugin_url()) /* phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet */ ?>/neo-draw--editor-excalidraw-custom-styles.css" /><!-- Style tag instead of enqueue function because it's required for the iframe. -->
            <script src="<?php echo esc_url(\NeoMotionBeta\NeoGlobal\plugin_url()) /* phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript */ ?>/neo-draw--excalidraw-thirdparty/react.js"></script><!-- Script tag instead of enqueue function because it's required for the iframe. -->
            <script src="<?php echo esc_url(\NeoMotionBeta\NeoGlobal\plugin_url()) /* phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript */ ?>/neo-draw--excalidraw-thirdparty/react-dom.js"></script><!-- Script tag instead of enqueue function because it's required for the iframe. -->
            <script src="<?php echo esc_url(\NeoMotionBeta\NeoGlobal\plugin_url()) /* phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript */ ?>/neo-draw--excalidraw-thirdparty/excalidraw.js"></script><!-- Script tag instead of enqueue function because it's required for the iframe. -->
            <script src="<?php echo esc_url(\NeoMotionBeta\NeoGlobal\plugin_url()) /* phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript */ ?>/neo-draw--editor-xml-formatter-thirdparty/neo-draw--editor-xml-formatter.min.js"></script><!-- Script tag instead of enqueue function because it's required for the iframe. -->
            <script src="<?php echo esc_url(\NeoMotionBeta\NeoGlobal\plugin_url()) /* phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript */ ?>/_global-web-component-importer.js" type="module"></script>
            <?php if ($neo_animate_web_component_importer_interface_ok) { ?><script src="<?php echo esc_url($neo_animate_web_component_importer_url) /* phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript */ ?>" type="module"></script><?php } ?> 
            <?php if ($neo_motion_web_component_importer_interface_ok) { ?><script src="<?php echo esc_url($neo_motion_web_component_importer_url) /* phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript */ ?>" type="module"></script><?php } ?> 
            <script src="<?php echo esc_url(\NeoMotionBeta\NeoGlobal\plugin_url()) /* phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript */ ?>/neo-draw--editor-index.js" type="module"></script><!-- Script tag instead of enqueue function because it's required for the iframe. -->
        </head>

        <body>
            <div id="app"></div>
        </body>
    </html><?php
});
