
@php

    if(!session('auth_redirect_url') || (session('auth_redirect_url') && session('disable_auth_redirect_overwrite' , 0) == 0 )){
            if(request()->headers->get('referer')){
                $url = request()->headers->get('referer');
                $domain = explode('/',str_replace(['https://','http://'],'',url()->current()))[0];
                if(!\Illuminate\Support\Str::contains($url,$domain)){
                    $url = url()->full();
                }
                session(['auth_redirect_url' => $url, 'disable_auth_redirect_overwrite' => 0 ]);
            }else{
                $url = url()->full();
                session(['auth_redirect_url' => $url, 'disable_auth_redirect_overwrite' => 0]);
            }
    }

    session(['auth_redirect_current' => url()->current() ]);

    $iframe_url = ecom('url')->prefix().'/account/auth';

    if(session('login') && request()->input('complete_profile') == 1){
        $iframe_url = route('complete-profile');
    }

@endphp

<iframe id="twa_auth_iframe" style="width: 100%;"
        scrolling="no"
        src="{{$iframe_url}}"  name="iframe_a" title="Login"></iframe>

<script>

    window.addEventListener('message', function (e) {
        const data = e.data;

        var obj = JSON.parse(data);
        var elem = document.getElementById("twa_auth_iframe");
        elem.style.height = obj.height + 'px';
        $(elem).contents().find('input[autofocus]').focus();
    });


</script>

