<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
$out = "<html>
<script>
    var targetWindow = window.parent;
    var data = " . wp_json_encode( $args['data'] ) . ";
    data.message_source = 'tami';

    if(typeof window.ReactNativeWebView !== 'undefined') {
        if(typeof window.ReactNativeWebView.postMessage === 'function') {
            targetWindow = window.ReactNativeWebView;
            data = JSON.stringify(data);
        }
    }
    targetWindow.postMessage(data, '*');
    if(window === targetWindow)
    {
        if(typeof data === 'object')
        {
            if(typeof data.message === 'string') {
                if(data.message) {
                    alert(data.message);
                }
            }
        }
        window.location.href = '" . esc_url( $args['redirect_url'] ) . "';
    }
</script>
</html>";

echo wp_kses( $out, [
	'html'   => array(),
	'script' => array()
] );