@extends($activeTemplate . 'layouts.app')

@section('panel')
    <main>
        <div class="account-section bg-img" data-background-image="{{ asset($activeTemplateTrue . 'images/account-bg.png') }}">
            @include('Template::user.auth.auth_sidebar')

            <div class="account-content">
                <form action="{{ route('user.register') }}" method="POST" class="account-form verify-gcaptcha disableSubmission">
                    @csrf
                    <div class="account-heading">
                        <a href="{{ route('home') }}" class="account-heading__logo">
                            <img class="logo-img" src="{{ siteLogo() }}" alt="Logo">
                        </a>
                        <h3 class="account-heading__title">@lang('Sign up')</h3>
                        <h5 class="account-heading__text">@lang('Start resolving issues by signing up.')</h5>
                    </div>
                    <div class="row">
                        <div class="form-group col-md-6">
                            <label class="form--label style-two">@lang('First Name')</label>
                            <input type="text" class="form--control md-style" name="firstname" value="{{ old('firstname') }}" required>
                        </div>
                        <div class="form-group col-md-6">
                            <label class="form--label style-two">@lang('Last Name')</label>
                            <input type="text" class="form--control md-style" name="lastname" value="{{ old('lastname') }}" required>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="form--label style-two">@lang('Mobile')</label>
                        <input type="text" class="form--control md-style checkUser" name="mobile" value="{{ old('mobile') }}" required>
                        <small class="text--danger mobileExist"></small>
                    </div>

                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="form--label style-two">@lang('E-Mail Address')</label>

                            <div class="input-wrapper">
                                <span class="input-wrapper__label-icon">
                                    <i class="fa-regular fa-envelope"></i>
                                </span>
                                <input type="email" class="form--control md-style checkUser" name="email" value="{{ old('email') }}" required>
                            </div>

                        </div>
                    </div>

                    <div class="form-group">
                        <label class="form--label style-two">@lang('Password')</label>
                        <div class="input-wrapper">
                            <span class="input-wrapper__label-icon">
                                @include('admin.partials.svg.lock')
                            </span>
                            <input type="password" name="password" class="form--control md-style" required>
                            <span class="password-show-hide fa-regular fa-eye toggle-password fa-eye-slash" id="#password"></span>
                        </div>

                    </div>

                    <div class="form-group">
                        <label class="form--label style-two">@lang('Confirm Password')</label>
                        <div class="input-wrapper">
                            <span class="input-wrapper__label-icon">
                                @include('admin.partials.svg.lock')
                            </span>
                            <input type="password" name="password_confirmation" class="form--control md-style" required>
                            <span class="password-show-hide fa-regular fa-eye toggle-password fa-eye-slash" id="#password_confirmation"></span>
                        </div>

                    </div>

                    <x-captcha />

                    @if (gs('agree'))
                        @php
                            $policyPages = getContent('policy_pages.element', false, orderById: true);
                        @endphp
                        <div class="form-group">
                            <div class="form--check">
                                <input type="checkbox" class="form-check-input" id="agree" @checked(old('agree')) name="agree" required>
                                <label class="form-check-label" for="agree"> @lang(' I agree with')
                                    <span class="ms-1">
                                        @foreach ($policyPages as $policy)
                                            <a href="{{ route('policy.pages', $policy->slug) }}" target="_blank">{{ __($policy->data_values->title) }}</a>
                                            @if (!$loop->last)
                                                ,
                                            @endif
                                        @endforeach
                                    </span>
                                </label>
                            </div>
                        </div>
                    @endif
                    <div class="form-group">
                        <button type="submit" id="recaptcha" class="btn btn--base btn--md w-100"> @lang('Register')</button>
                    </div>
                    <p class="mb-0 fs-14">@lang('Already have an account?') <a href="{{ route('user.login') }}">@lang('Login')</a></p>
                </form>

            </div>
        </div>
    </main>

    <div class="modal custom--modal fade" id="existModalCenter" tabindex="-1" role="dialog" aria-labelledby="existModalCenterTitle" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="existModalLongTitle">@lang('You are with us')</h5>
                    <span type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                        <i class="las la-times"></i>
                    </span>
                </div>
                <div class="modal-body">
                    <h6 class="text-center">@lang('You already have an account please Login ')</h6>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-dark btn--sm" data-bs-dismiss="modal">@lang('Close')</button>
                    <a href="{{ route('user.login') }}" class="btn btn--base btn--sm">@lang('Login')</a>
                </div>
            </div>
        </div>
    </div>
@endsection


@push('script')
    <script>
        "use strict";
        (function($) {

            $('.checkUser').on('focusout', function(e) {
                var url = '{{ route('user.checkUser') }}';
                var value = $(this).val();
                var token = '{{ csrf_token() }}';
                var inputName = $(this).attr('name');
                var data = {
                    _token: token
                };

                if (inputName === 'mobile') {
                    data.mobile = value;
                } else if (inputName === 'email') {
                    data.email = value;
                }

                $('.mobileExist').text('');

                $.post(url, data, function(response) {
                    if (response.data != false && response.type == 'mobile') {
                        $('.mobileExist').text(`@lang('Mobile already exists')`);
                    }

                    if (response.data != false && response.type == 'email') {
                        $('#existModalCenter').modal('show');
                    }
                });
            });

        })(jQuery);
    </script>
@endpush
