@extends('layouts.layout-2')

@section('content')
    <h4 class="font-weight-bold py-2 mb-2 d-flex justify-content-between align-items-center w-100 ">
        <div>{{ __('navigation.my_homeparty') }} /
            @if(!$homeparty->id)
                anlegen
            @else
                {{ __('navigation.manage') }}

            @endif
        </div>
        <a href="{{route('user_homepartys')}}" class="btn btn-sm btn-default float-right">zurück</a>
    </h4>

        {!! Form::open(['url' => route('user_homeparty_detail', [$homeparty->id]), 'class' => 'form-horizontal', 'id'=>'homeparty-party-form-validation']) !!}

        <div class="card mb-4">
            <h5 class="card-header">
                <div class="row">
                        @if(!$homeparty->id)
                            <div class="col-12">
                            Neue Homeparty anlegen
                            </div>
                        @else
                            <div class="col-12">
                                <div class="d-flex justify-content-between align-items-center w-100">
                                    <div>Homeparty verwalten</div>
                                    <div class="float-right">
                                        <a href="{{route('user_homeparty_guests', [$homeparty->id])}}" class="btn btn-sm btn-secondary mr-2 mb-1"><i class="ion ion-md-person-add"></i> Gäste anlegen</a>
                                        <a href="{{route('user_homeparty_order', [$homeparty->id])}}" class="btn btn-sm btn-secondary mr-2 mb-1"><i class="ion ion-md-basket"></i> Bestellung</a>
                                    </div>
                                </div>
                            </div>
                        @endif
                </div>
            </h5>

            <div class="card-body">
                <div class="form-row">
                    <div class="form-group col-md-4  {{ $errors->has('name') ? 'has-error' : '' }}">
                        <label for="name" class="form-label">{{ __('Veranstaltungsname') }}*</label>
                        {{ Form::text('name', $homeparty->name,  array('placeholder'=>__('Veranstaltungsname'), 'class'=>'form-control', 'required')) }}
                        @if ($errors->has('name'))
                            <span class="help-block">
                                <strong>{{ $errors->first('name') }}</strong>
                            </span>
                        @endif
                    </div>
                    <div class="form-group col-md-4  {{ $errors->has('date') ? 'has-error' : '' }}">
                        <label for="date" class="form-label">{{ __('Veranstaltungsdatum') }}*</label>
                        {{ Form::text('date', $homeparty->date,  array('placeholder'=>Util::formatDate(), 'data-date-format'=>Util::formatDate(), 'data-start_view'=>2, 'class'=>'form-control datepicker-base',  'required')) }}
                        @if ($errors->has('date'))
                            <span class="help-block">
                            <strong>{{ $errors->first('date') }}</strong>
                            </span>
                        @endif
                    </div>
                    <div class="form-group col-md-4  {{ $errors->has('place') ? 'has-error' : '' }}">
                        <label for="place" class="form-label">{{ __('Veranstaltungsort') }}*</label>
                        {{ Form::text('place', $homeparty->place,  array('placeholder'=>__('Veranstaltungsort'), 'class'=>'form-control', 'required')) }}
                        @if ($errors->has('place'))
                            <span class="help-block">
                            <strong>{{ $errors->first('place') }}</strong>
                            </span>
                        @endif
                    </div>

                </div>
                <div class="form-group">
                    <label class="form-label" for="description">{{ __('Beschreibung') }}</label>
                    {{ Form::textarea('description', $homeparty->description ,  array('placeholder'=>__('Beschreibung'), 'class'=>'form-control', 'rows'=>2)) }}
                </div>
            </div>
        </div>
        <div class="text-left mt-3">
            <button type="submit" class="btn btn-secondary mr-2 mb-2" name="action" value="homeparty-party-store">
                @if($homeparty->id) {{ __('Änderungen speichern') }} @else {{ __('speichern') }} @endif</button>&nbsp;
            <a href="{{route('user_homepartys')}}" class="btn btn-default mb-2">zurück zur Übersicht</a>
        </div>
        {!! Form::close() !!}


        @if($homeparty->id)
            <div class="card mb-3 mt-2">
                <div class="col-md-12 px-4 pt-4">
                    <h6 class="mb-4">Lass den Gastgeber/in seine Daten selber ausfüllen</h6>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-prepend">
                              <button class="btn btn-secondary" type="button" title="Kopiert!" data-clipboard-demo data-clipboard-target="#homeparty_link"><i class="ion ion-ios-copy"></i> Link kopieren</button>
                            </span>
                            <input type="text" class="form-control" name="homeparty_link" value="{{ $homeparty->getTokenLink() }}" id="homeparty_link" placeholder="">
                        </div>
                    </div>
                    <p>Teile diesen Link mit dem Gastgeber/in und Gästen (z.B. WhatsApp oder SMS), damit gelangt sie auf eine Zielseite wo sie ihre Daten selber ausfüllen können. Nutze das „Kopier-Symbol“, um den Link gleich in Deine Zwischenablage zu kopieren.</p>
                </div>
            </div>
            <hr>
            {!! Form::open(['url' => route('user_homeparty_detail', [$homeparty->id]), 'class' => 'form-horizontal', 'id'=>'homeparty-user-form-validation']) !!}
            <div class="card mb-4">
                <h5 class="card-header">
                    <div class="row">
                        <div class="col-xs-12 col-sm-6">
                            Gastgeber-, Rechungsadresse
                        </div>
                        <div class="col-xs-12 col-sm-6">
                            <span class="text-tiny float-right">* {{trans('register.required_fields')}}</span>
                            <span class="d-none d-lg-inline">Lieferadresse</span>
                        </div>
                    </div>
                </h5>
                @include('user.homeparty._edit')
            </div>
            <div class="text-left mt-3">
                <button type="submit" class="btn btn-secondary mr-2 mb-2" name="action" value="homeparty-user-store">{{ __('save') }}</button>&nbsp;
                <a href="{{route('user_homepartys')}}" class="btn btn-default mb-2">zurück zur Übersicht</a>
            </div>
            {!! Form::close() !!}
        @endif



    <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( "Geben Sie bitte maximal {0} Zeichen ein." ),
                minlength: $.validator.format( "Geben Sie bitte mindestens {0} Zeichen ein." ),
                rangelength: $.validator.format( "Geben Sie bitte mindestens {0} und maximal {1} Zeichen ein." ),
                email: "Geben Sie bitte eine gültige E-Mail Adresse ein.",
                url: "Geben Sie bitte eine gültige URL ein.",
                date: "Bitte geben Sie ein gültiges Datum ein.",
                number: "Geben Sie bitte eine Nummer ein.",
                digits: "Geben Sie bitte nur Ziffern ein.",
                equalTo: "Bitte denselben Wert wiederholen.",
                range: $.validator.format( "Geben Sie bitte einen Wert zwischen {0} und {1} ein." ),
                max: $.validator.format( "Geben Sie bitte einen Wert kleiner oder gleich {0} ein." ),
                min: $.validator.format( "Geben Sie bitte einen Wert größer oder gleich {0} ein." ),
                creditcard: "Geben Sie bitte eine gültige Kreditkarten-Nummer ein."
            });



            // Set up validator
            $('#homeparty-party-form-validation').validate({
                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.')}}",
                },
                onkeyup: false
            });

            // Set up validator
            $('#homeparty-user-form-validation').validate({
                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.')}}",
                    },
                    zipcode : {
                        required: "{{__('This field is required.')}}",
                    },
                    address : {
                        required: "{{__('This field is required.')}}",
                    },
                    city : {
                        required: "{{__('This field is required.')}}",
                    }
                },
                onkeyup: false
            });

        });
    </script>
    <script>
        $( document ).ready(function() {
            var clipboardDemos = new ClipboardJS('[data-clipboard-demo]');
            clipboardDemos.on('success', function (e) {
                e.clearSelection();
                $(e.trigger).tooltip('enable').tooltip('show');
            });
            clipboardDemos.on('error', function (e) {
                console.error('Action:', e.action);
                console.error('Trigger:', e.trigger);
            });

            $('button[data-clipboard-demo]').on('mouseout', function () {
                $(this).tooltip('disable');
            })
        });
    </script>
@endsection