<?php

defined( 'ABSPATH' ) || exit;

$id = wp_rand( 10, 9999 );

if ( ! empty( $is_preview ) ) {
    $draft         = ! empty( $form->draft ) ? json_decode( $form->draft ) : null;
    $draft_content = $draft ? $draft->content : null;

    if ( $draft_content ) {
        $form->content = wp_json_encode( $draft_content );
    }
}

?>

<div class="helpgent-app helpgent-form <?php ! empty( $full_screen ) ? helpgent_render( "helpgent-fullscreen" ) : '' ?>" 
data-form_data="<?php helpgent_render( htmlspecialchars( json_encode( $form ), ENT_QUOTES, 'UTF-8' ) );?>"
data-is_preview_active="<?php helpgent_render( ! empty( $is_preview ) ? 1 : 0 )?>"
id="helpgent-form-<?php helpgent_render( $id ) ?>"
></div>
<script data-cfasync="false" type="text/javascript">

if( document.readyState === "complete" || document.readyState === "interactive" ) {
    window.dispatchEvent( new CustomEvent( 'load-helpgent-shortcode', {detail: {formId: <?php helpgent_render( $id ) ?>}} ) );
} else {
    window.addEventListener( 'load', function() {
        window.dispatchEvent( new CustomEvent( 'load-helpgent-shortcode', {detail: {formId: <?php helpgent_render( $id ) ?>}} ) );
    } )
}
</script>
