<?php
/**
 * WeCodeArt Framework.
 *
 * WARNING: This file is part of the core WeCodeArt Framework. DO NOT edit this file under any circumstances.
 * Please do all modifications in the form of a child theme.
 *
 * @package		WeCodeArt Framework
 * @subpackage  Toast
 * @since		6.4.5
 * @version    	6.4.5
 */

defined( 'ABSPATH' ) || exit;

$classnames = [ 'wp-site-toasts', 'position-fixed', 'p-3', 'bottom-0', 'end-0' ];

\wecodeart( 'styles' )->Components->load( [ 'toast' ] );
\wecodeart( 'styles' )->Utilities->load( $classnames );

\wp_enqueue_script( 'wecodeart-support-assets-toast' );

\wp_enqueue_script_module( '@wecodeart/toast' );

\wp_interactivity_state( 'wecodeart/toast', apply_filters( 'wecodeart/filter/interactive/state/toast', [
	'elements'	=> [],
    'options'   => []
] ) );
	
\wp_interactivity_config( 'wecodeart/toast', [
	'elements'	=> 'array',
    'options'   => '(object|array)'
] );

// Container goes to footer.
\add_action( 'wp_footer', static function() use ( $classnames ) {
?>
<div
    class="<?php echo esc_attr( join( ' ', $classnames ) ); ?>"
    data-wp-interactive="wecodeart/toast"
    data-wp-context="{}"
    data-wp-init="callbacks.validateConfig"
    data-wp-watch="callbacks.onAdd"
    aria-live="polite"
    aria-atomic="true"
></div>
<?php
}, PHP_INT_MIN );

// JS template needed later.
\add_action( 'wp_footer', static function() {
?>
<script type="text/template" id="wp-toast-template">
    <div class="wp-toast" role="alert" aria-live="assertive" aria-atomic="true">
        <div class="wp-toast__header">
            <span class="wp-toast__header-text"></span>
            <?php wecodeart_template( 'general/close', [ 'close' => 'toast' ] ); ?>

        </div>
        <div class="wp-toast__body"></div>
    </div>
</script>
<?php
}, PHP_INT_MAX );