@extends('EcomAuthViews::layouts.authentication.layout')


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

    <form class="twa-form twa-login disable-on-submit" method="POST" action="{{route('account-auth', ['type' => $type])}}">
        @csrf

        @if(request()->input('title') && request()->input('notification'))
            <div class="invalid-field">{{ request()->input('notification') }}</div>
            <sep></sep>
        @endif

        @if($type == "phone")

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

{{--            @component('EcomGeneralViews::components.form.input', [ "parentClass" => "", "size" => "full", "type" => "text", "label" => ___('authentication.phone_number') ])--}}
{{--                <input class="phone-field" required--}}
{{--                       data-custom-container="" data-allow-dropdown="true"--}}
{{--                       data-autohide-dialcode="true" data-format="true" data-national-mode="true" placeholder=" "--}}
{{--                       name="phone" data-initial-country="{{$country_code ?? old('phone_country_code') }}"--}}

{{--                       @if(isset($phone_value) && $phone_value != '') value="{{$phone_value}}" @else  value="{{old('phone')}}" @endif--}}
{{--                />--}}
{{--                <input type="hidden" name="phone_country_code" class="phone_country_code" value="{{old('phone_country_code')}}"/>--}}

{{--                <span class="invalid-field"> @error('phone') {{$message}}  @enderror </span>--}}
{{--            @endcomponent--}}

        @component('EcomAuthViews::components.phone' , [ 'parent_class' => app()->getLocale() ,'phone_value' => isset($phone_value) ? $phone_value : '','country_code' => isset($country_code) ? $country_code : null ]) @endcomponent

       @elseif($type == "email")

           @component('EcomGeneralViews::components.form.input', [ "parentClass" => "", "size" => "full", "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" => "full", "type" => "submit", "label" => "" ])
           <input type="submit" value="{{ ___('authentication.continue') }}"/>
       @endcomponent
   </form>

   @foreach($available_login_methods as $method)
       <a href="{{$method['href']}}" class="icon-button">
           <div class="icon">
               @php try { @endphp
                   @include("EcomAuthViews::icons.".$method['icon'])
               @php }catch(\Throwable $th){} @endphp
           </div>
           <div class="text">{{ $method['label'] }}</div>
           <div class="icon"></div>
       </a>
   @endforeach

@endsection
@section('scripts')
   <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
