
<div class="card mb-4">
    <h5 class="card-header">
        {{ __('Rechnungsdaten') }}
        <span class="text-tiny float-right">* {{trans('register.required_fields')}}</span>
    </h5>
    <div class="card-body">
        <input type="hidden" name="user_id" value="{{$user->id}}">

        <div class="row">
            <div class="col-12 col-lg-6">
                <div class="form-row">
                    <div class="form-group col-md-12">
                        <label for="company" class="form-label">{{ __('Company name') }} (optional)</label>
                        {{ Form::text('company', $user->account->company,  array('placeholder'=>__('Company name'), 'class'=>'form-control', 'id'=>'company', 'tabindex' => 1)) }}
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group col-md-6 {{ $errors->has('salutation') ? 'has-error' : '' }}">
                        <label class="form-label">{{ __('Salutation') }}*</label>
                        <select class="selectpicker" data-style="btn-light" name="salutation" id="salutation" required tabindex="2">
                            {!!  HTMLHelper::getSalutation($user->account->salutation) !!}
                        </select>
                        @if ($errors->has('salutation'))
                            <span class="help-block">
                            <strong>{{ $errors->first('salutation') }}</strong>
                    </span>
                        @endif
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group col-md-6 {{ $errors->has('first_name') ? 'has-error' : '' }}">
                        <label class="form-label" for="first_name">{{ __('First name') }}*</label>
                        {{ Form::text('first_name', $user->account->first_name,  array('placeholder'=>__('First name'), 'class'=>'form-control', 'id'=>'first_name', 'required'=>true, 'tabindex' => 4)) }}
                        @if ($errors->has('first_name'))
                            <span class="help-block">
                            <strong>{{ $errors->first('first_name') }}</strong>
                    </span>
                        @endif

                    </div>
                    <div class="form-group col-md-6  {{ $errors->has('last_name') ? 'has-error' : '' }}">
                        <label class="form-label" for="last_name">{{ __('Last name') }}*</label>
                        {{ Form::text('last_name', $user->account->last_name,  array('placeholder'=>__('Last name'), 'class'=>'form-control', 'id'=>'last_name', 'required'=>true, 'tabindex' => 5)) }}
                        @if ($errors->has('last_name'))
                            <span class="help-block">
                            <strong>{{ $errors->first('last_name') }}</strong>
                    </span>
                        @endif

                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group col-md-12 {{ $errors->has('address') ? 'has-error' : '' }}">
                        <label class="form-label" for="address">{{ __('Street') }} / {{ __('House number') }}</label>
                        {{ Form::text('address', $user->account->address,  array('placeholder'=>__('Street'), 'class'=>'form-control', 'id'=>'address', 'tabindex' => 6)) }}
                        @if ($errors->has('address'))
                            <span class="help-block">
                                <strong>{{ $errors->first('address') }}</strong>
                        </span>
                        @endif
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group col-md-12  {{ $errors->has('address_2') ? 'has-error' : '' }}">
                        <label class="form-label" for="address_2">{{ __('Wohnung / Gebäude  (optional)') }}</label>
                        {{ Form::text('address_2', $user->account->address_2,  array('placeholder'=>__('Wohnung / Gebäude  (optional)'), 'class'=>'form-control', 'id'=>'address_2', 'tabindex' => 6)) }}
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group col-md-6  {{ $errors->has('zipcode') ? 'has-error' : '' }}">
                        <label class="form-label" for="zipcode">{{ __('Postcode') }}</label>
                        {{ Form::text('zipcode', $user->account->zipcode,  array('placeholder'=>__('Postcode'), 'class'=>'form-control', 'id'=>'zipcode', 'tabindex' => 7)) }}
                        @if ($errors->has('zipcode'))
                            <span class="help-block">
                            <strong>{{ $errors->first('zipcode') }}</strong>
                            </span>
                        @endif
                    </div>
                    <div class="form-group col-md-6  {{ $errors->has('city') ? 'has-error' : '' }}">
                        <label class="form-label" for="city">{{ __('City') }}</label>
                        {{ Form::text('city', $user->account->city,  array('placeholder'=>__('City'), 'class'=>'form-control', 'id'=>'city', 'tabindex' => 8)) }}
                        @if ($errors->has('city'))
                            <span class="help-block">
                            <strong>{{ $errors->first('city') }}</strong>
                            </span>
                        @endif
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group col-md-6  {{ $errors->has('country_id') ? 'has-error' : '' }}">
                        <label class="form-label">{{ __('Country') }}*</label>
                        <select class="selectpicker" name="country_id" id="country_id"  data-style="btn-light" data-live-search="true" required tabindex="9">
                            {!!  HTMLHelper::getContriesWithMore($user->account->country_id) !!}
                        </select>
                        @if ($errors->has('country_id'))
                            <span class="help-block">
                            <strong>{{ $errors->first('country_id') }}</strong>
                    </span>
                        @endif
                    </div>
                    <div class="form-group col-md-6">
                        <label for="birthday" class="form-label">{{ __('Geburtsdatum') }}</label>
                        {{ Form::text('birthday', $user->account->birthday,  array('placeholder'=>Util::formatDate(), 'data-date-format'=>Util::formatDate(), 'data-start_view'=>2, 'class'=>'form-control datepicker-birthday')) }}
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group col-md-4">
                        <label class="form-label" for="pre_phone_id">{{ __('Country code') }}</label>
                        <select class="selectpicker" name="pre_phone_id" id="pre_phone_id"  data-style="btn-light" data-live-search="true" tabindex="10">
                            {!!  HTMLHelper::getContriesCodes($user->account->pre_phone_id) !!}
                        </select>
                    </div>
                    <div class="form-group col-md-8 {{ $errors->has('phone') ? 'has-error' : '' }}">
                        <label class="form-label" for="phone">{{ __('Phone') }}</label>
                        {{ Form::text('phone', $user->account->phone,  array('placeholder'=>__('Phone'), 'class'=>'form-control', 'id'=>'phone', 'tabindex' => 11)) }}
                    </div>
                </div>
                <div class="form-row">
                    <div class="form-group col-md-4">
                        <label class="form-label" for="pre_mobil_id">{{ __('Country code') }}</label>
                        <select class="selectpicker" name="pre_mobil_id" id="pre_mobil_id"  data-style="btn-light" data-live-search="true" tabindex="12">
                            {!!  HTMLHelper::getContriesCodes($user->account->pre_mobil_id) !!}
                        </select>
                    </div>
                    <div class="form-group col-md-8 {{ $errors->has('mobil') ? 'has-error' : '' }}">
                        <label class="form-label" for="mobil">{{ __('Mobile Phone') }}</label>
                        {{ Form::text('mobil', $user->account->mobil,  array('placeholder'=>__('Mobile Phone'), 'class'=>'form-control', 'id'=>'mobil', 'tabindex' => 13)) }}
                    </div>
                </div>
            </div>
            <div class="col-12 col-lg-6">
                <hr>
                <div class="form-group">
                    <label class="custom-control custom-checkbox m-0">
                        <input type="checkbox" class="custom-control-input" name="same_as_billing" id="same_as_billing" checked="checked" disabled>
                        <span class="custom-control-label">{{__('Versand an die gleiche Adresse')}}</span>
                    </label>
                </div>
            </div>
        </div>
        <hr>

        <div class="form-row">
                <div class="form-group col-md-6">
                    <label class="form-label" for="email">{{ __('E-Mail Address') }}*</label>
                    {{ Form::text('email', $user->email,  array('placeholder'=>'E-Mail', 'class'=>'form-control', 'required'=>true, 'id'=>'email', 'tabindex' => 14)) }}
                </div>
                <div class="form-group col-md-6">
                    <label class="form-label" for="email-confirm">{{ __('Confirm E-Mail') }}*</label>
                    {{ Form::text('email-confirm', $user->email,  array('placeholder'=>__('Confirm E-Mail'), 'class'=>'form-control', 'required'=>true, 'id'=>'email-confirm', 'tabindex' => 15)) }}
                </div>
            </div>
    </div>
</div>
{{ Form::hidden('same_as_billing', 1) }}

<script type="application/javascript">

    $( document ).ready(function() {

        // Shipping Address show|hide
        $("#same_as_billing").on("change", function () {
            $('#show_shipping_address').slideToggle(200, function () {

                // scroll down to shipping area.
                if ($('#show_shipping_address').is(":visible")) {
                    _scrollTo('#show_shipping_address', 20);
                }
            });
        });

    
        $.extend( $.validator.messages, {
            required: "Dieses Feld ist ein Pflichtfeld.",
            maxlength: $.validator.format( "Gib bitte maximal {0} Zeichen ein." ),
            minlength: $.validator.format( "Gib bitte mindestens {0} Zeichen ein." ),
            rangelength: $.validator.format( "Gib bitte mindestens {0} und maximal {1} Zeichen ein." ),
            email: "Gib bitte eine gültige E-Mail Adresse ein.",
            url: "Gib bitte eine gültige URL ein.",
            date: "Bitte gib ein gültiges Datum ein.",
            number: "Gib bitte eine Nummer ein.",
            digits: "Gib bitte nur Ziffern ein.",
            equalTo: "Bitte denselben Wert wiederholen.",
            range: $.validator.format( "Gib bitte einen Wert zwischen {0} und {1} ein." ),
            max: $.validator.format( "Gib bitte einen Wert kleiner oder gleich {0} ein." ),
            min: $.validator.format( "Gib bitte einen Wert größer oder gleich {0} ein." ),
            creditcard: "Gib bitte eine gültige Kreditkarten-Nummer ein."
        });

        // Set up validator
        $('#lead-form-validation').validate({
            rules: {
                'email': {
                    required: true,
                    email: true,
                    remote:
                        {
                            url: "{{ route('user_check_mail') }}",
                            type: "post",
                            data:
                                {
                                    user_id: function()
                                    {
                                        return $('#lead-form-validation :input[name="user_id"]').val();
                                    },
                                    email: function()
                                    {
                                        return $('#lead-form-validation :input[name="email"]').val();
                                    }
                                },
                            encode: true,
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                        }
                },
                'email-confirm': {
                    required: true,
                    equalTo: "#email"
                },
            },
            errorPlacement: function errorPlacement(error, element) {
                $(element).parents('.form-group').append(
                    error.addClass('invalid-feedback small d-block')
                )
            },
            highlight: function (element) {
                if ($(element).hasClass('selectpicker')) {
                    $(element).parent().addClass('is-invalid');
                }
                $(element).addClass('is-invalid');
            },
            unhighlight: function (element) {
                $(element).removeClass('is-invalid');
                $(element).parents('.form-group').find('.is-invalid').removeClass('is-invalid');
            },
            messages :  {
                required: "{{__('This field is required.')}}",
                country_id : {
                    required: "{{__('This field is required.')}}",
                },
                salutation : {
                    required: "{{__('Bitte angeben.')}}",
                },
                first_name : {
                    required: "{{__('This field is required.')}}",
                },
                last_name : {
                    required: "{{__('This field is required.')}}",
                },
                equalTo : "{{__('Please enter the same value again.')}}",
                'email-confirm' : {
                    equalTo : "{{__('Please enter the same value again.')}}",
                    required: "{{__('This field is required.')}}",
                },
                email: {
                    required : "{{__('This field is required.')}}",
                    email: "{{ __('Please enter a valid email address.') }}",
                    remote : "{{ __('This E-mail is already in use.') }}"
                },
            },
            onkeyup: false
        });

    });
</script>
