@extends('EcomAuthViews::layouts.authentication.layout',[ "withoutWrapper" => true, 'heightAdjuster' => 0 ])


@section('content')

    @php
        // $input_errors = session('res_bag');
    @endphp

    <div class="twa-checkout-stacked-title"><h2>Contact Details</h2></div>
    <form class="twa-form twa-login" method="POST" style="gap:15px !important;;" action="{{route('account-auth', ['type' => $type])}}">
        @csrf
        <input type="hidden" name="guest" value="1">
        @if($type == "phone")

            {{--            @component('EcomAuthViews::components.phone' , ['phone_value' => isset($phone_value) ? $phone_value : '' ] )--}}

            @component('EcomGeneralViews::components.form.input', [ "parentClass" => "", "size" => "third", "type" => "text", "label" => ___('authentication.email') ])
                <input name="email" required value="{{old('email')}}"
                       placeholder="{{ ___('authentication.email') }}"></input>
                @error('email') <span> {{$message}}</span> @enderror
            @endcomponent
            @component('EcomGeneralViews::components.form.input', [ "parentClass" => "", "size" => "third", "type" => "text" ])
                @component('EcomAuthViews::components.phone' , ['phone_value' => isset($phone_value) ? $phone_value : '','country_code' => isset($country_code) ? $country_code : null ]) @endcomponent
            @endcomponent

        @elseif($type == "email")

            @component('EcomGeneralViews::components.form.input', [ "parentClass" => "", "size" => "half", "type" => "text", "label" => ___('authentication.email') ])
                <input name="email" required value="{{old('email')}}"
                       placeholder="{{ ___('authentication.email') }}"></input>
                <span class="invalid-field"> @error('email') {{$message}}  @enderror </span>

            @endcomponent

        @endif
        @component('EcomGeneralViews::components.form.input', [ "parentClass" => "", "size" => "third", "type" => "text" ])
            @component('EcomGeneralViews::components.form.input', [ "parentClass" => "hide-label-sm", "size" => "full", "type" => "submit", "label" => "" ])
                <div class="twa-ecom-label">&nbsp;</div>
                <input type="submit" value="{{ ___('authentication.continue') }}" class="inline" />
            @endcomponent
        @endcomponent

    </form>



@endsection
@section('scripts')
    <style>
        .twa-authentication-form{ max-width: 100% !important; }
    </style>
    <script>

        function str_replace(find, replace , str) {
            return str.replace(new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), replace);
        }

        $(document).ready(function () {
            AUTHENTICATION_InitCodeGroup('code-input-group');

            $('input[name=phone]').on('input',function() {
                this.value = this.value.replace(/[^0-9\+]/g, '');
                if (this.value.lastIndexOf("+") > 0) {
                    this.value = (this.value.charAt(0) == "+" ? "+" : "") + str_replace("+" , "" , this.value);
                }
                $(this).parents('.twa-ecom-field-control').find('.invalid-field').text('');
            });
        });

    </script>
@endsection
