@extends('web.layouts.container')

@section('content')
    <section class="register-pg">
        <div class="container">
            <div class="inner">
                <div class="row">
                    <div class="col-md-6">
                        <div class="logo-box">
                            <img src="{{asset('assets/web/images/logo.svg')}}" alt="" class="logo"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="text-box">
                            <div class="links-top mb-5">
                                <a href="{{route('user.login')}}" class="link {{session('login') == 'yes' ? 'active' : ''}}">{{__('members.login')}}</a>
                                <a href="{{route('user.register')}}" class="link {{session('login') == 'no' ? 'active' : ''}}">{{__('members.register')}}</a>
                            </div>
                            <p class="p text-center mt-4 mb-4">{{__('members.login_register_hint')}}  </p>
                            <form method="post" action="{{route('user.doRegAndLogin')}}" class="register_login_form">
                                <div class="form-group">
                                    <input name="phone" class="form-control" type="tel" placeholder="{{__('members.phone')}}"/>
                                </div>
                                <div class="mt-5">
                                    <button class="butn m-auto d-block register_login_button"><span><b>{{$buttonTitle}}</b></span></button>
                                </div>
                                <p class="another_opt text-center mt-4">{{__('members.dont_have_account')}} <a href="{{route('user.register')}}">{{__('members.register')}}</a></p>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection

@section('inner_js')

    <script>
        $('.register_login_button').click(async function (e) {
            e.preventDefault();
            $(this).attr('disabled', true);
            let form = $('.register_login_form'),
                data = new FormData(form[0]),
                url = form.attr('action'),
                method = form.attr('method');

            const response=await ajax({
                url,
                data,
                dataType: 'json',
                method,
                contentType: false,
                processData: false,
            });

            if (response.errors) {
                $(this).attr('disabled', false);
                toasterError(response.errors);
            }
            if (response.url) {
                window.location.href = response.url;
            }
        });
    </script>

@endsection
