@extends('web.layouts.layout')

@section('content')

    @if ($errors->any())
        <div class="row">
            <div class="col-sm-12">
                <div class="alert alert-danger">
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            </div>
        </div>
    @endif


    {!! Form::open(['action' => route('web_promotion_store', $promotion_user->id), 'class' => 'form-horizontal form-prevent-multiple-submits', 'id' => 'user-reminder-form-validations']) !!}

    <div class="layout-content">
        @include('web.promotion._intro')

        <div class="container px-3">
            @include('web.promotion._reminder_service')

            @include('web.promotion._show_around')
        </div>
    </div>
    {!! Form::close() !!}

  
    <script>
        $(document).ready(function() {

            var validator = $("#user-reminder-form-validations").validate({
                submitHandler: function(form) {
                    console.log('asd');
                    console.log(form);
                    $('.button-prevent-multiple-submits').attr('disabled', true);
                    $('.button-prevent-multiple-submits').find('.spinner').show();
                    form.submit();
                },
                errorPlacement: function errorPlacement(error, element) {
                    var placement = $(element).data('error');
                    if (placement) {
                        $(placement).append(error.addClass('invalid-feedback d-block'));
                    } else {
                        error.insertAfter(element).addClass('invalid-feedback small d-block');
                    }
                },
                highlight: function( element, errorClass, validClass ) {
                    if($(element).hasClass('selectpicker')){
                        $(element).parent('.form-control').find('.dropdown-toggle').addClass( errorClass ).removeClass( validClass );
                    }else if ( element.type === "radio" ) {
                        this.findByName( element.name ).addClass( errorClass ).removeClass( validClass );
                    } else {
                        $( element ).addClass( errorClass ).removeClass( validClass );
                    }
                },
                unhighlight: function( element, errorClass, validClass ) {
                    if($(element).hasClass('selectpicker')){
                        $(element).parent('.form-control').find('.dropdown-toggle').removeClass( errorClass ).addClass( validClass );
                    } else if ( element.type === "radio" ) {
                        this.findByName( element.name ).removeClass( errorClass ).addClass( validClass );
                    } else {
                        $( element ).removeClass( errorClass ).addClass( validClass );
                    }
                }
            });

            $('select.revalidat').on('change', function () {
                validator.element($(this));
            });

            $('.switcher-holder').on('click', function() {
                $(this).find('.switcher-input').prop('checked', true);
            });
        });
    </script>

@endsection
