@extends('layouts.layout-2')

@section('content')

    <style>
        .btn-xs {
            line-height: 1em;
        }
    </style>
    <h4 class="font-weight-bold py-3 mb-1">
        Buchung verwalten
    </h4>


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

    <input type="hidden" name="id" id="id" value="{{$id}}">

    <!-- draft -->
    <div class="card mb-2">
        <div class="card-body row">
            <div class="form-group col-sm-6">
                <label class="form-label" for="merlin_order_number">{{ __('MyJack Nr.') }}*</label>
                {{ Form::text('merlin_order_number', $booking->merlin_order_number,  array('placeholder'=>__('MyJack Nr.'), 'class'=>'form-control', 'id'=>'merlin_order_number')) }}
            </div>

            <div class="form-group col-sm-6">
                <label class="form-label" for="booking_id">{{ __('Nr.') }}*</label>
                {{ Form::text('id', $booking->id,  array('placeholder'=>__('Nr.'), 'class'=>'form-control', 'id'=>'booking_id', 'readonly')) }}
            </div>

            <div class="form-group col-sm-6">
                <label class="form-label" for="booking_id">{{ __('Gesamtpreis Organisation') }}</label>
                <div class="input-group">
                    <div class="input-group-prepend">
                        <span class="input-group-text">€</span>
                    </div>
                    {{ Form::text('price', $booking->price,  array('placeholder'=>__('Gesamtpreis'), 'class'=>'form-control', 'id'=>'price', 'readonly')) }}
                </div>
            </div>
        </div>
    </div>


    <div class="text-left mt-3">
        <button type="submit" name="action" value="saveAll" class="btn btn-submit">{{ __('save changes') }}</button>&nbsp;
        <a href="{{route('bookings')}}" class="btn btn-default">{{ __('zur Übersicht') }}</a>
        <a href="{{ make_old_url('/index.php/booking/'.$booking->id.'/edit') }}" class="btn btn-default float-right">{{ __('zurück ins CRM v2') }}</a>
    </div>
    <hr>

    @if($booking->new_drafts )

        @php($i = 1)
        <div class="text-right mb-2">
            <button type="submit" name="action" value="addItemUp" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i> Neue Leistung hinzufügen <i class="fa fa-arrow-up"></i></button>
        </div>
        <div id="dragula-drag-handles">
        @foreach($booking->booking_draft_items as $booking_draft_item)
        <!-- item -->
        <div class="card mb-2"  @if($booking_draft_item->draft_type) style="background-color: {{ $booking_draft_item->draft_type->color }}" @endif>
            <span class=" handle ion ion-ios-move d-inline-block bg-light text-dark p-1">
                    <div class="float-left ml-1 mr-1">#{{ $i++ }} </div>
                    <div class="float-right">
                    <button type="submit" name="action" value="up_{{$booking_draft_item->id}}" class="btn btn-xs btn-primary py-0"><i class="fa fa-arrow-up"></i> </button>
                    <button type="submit" name="action" value="down_{{$booking_draft_item->id}}" class="btn btn-xs btn-primary mr-2"><i class="fa fa-arrow-down"></i> </button>
                    </div>
            </span>

            <div class="card-body row" style="">
                <div class="form-group col-12 col-sm-6 col-md-2 col-lg-2">
                    <select class="selectpicker" data-style="btn-light" name="draft_item[{{$booking_draft_item->id}}][draft_type_id]" id="draft_item_{{$booking_draft_item->id }}_draft_type_id" data-live-search="true" required>
                        <option value="" disabled>Vorlagen-Typ*</option>
                        {!!  HTMLHelper::getDraftTypes($booking_draft_item->draft_type_id) !!}
                    </select>
                </div>

                <div class="form-group col-6 col-sm-3 col-md-2 col-lg-2">
                    {{ Form::text('draft_item['.$booking_draft_item->id.'][start_date]', $booking_draft_item->start_date,  array('placeholder'=>__('Start Datum'), 'class'=>'form-control datepicker-base', 'id'=>'draft_item_'.$booking_draft_item->id.'_start_dat')) }}
                </div>

                <div class="form-group col-6 col-sm-3 col-md-2 col-lg-2">
                    {{ Form::text('draft_item['.$booking_draft_item->id.'][end_date]', $booking_draft_item->end_date,  array('placeholder'=>__('End Datum'), 'class'=>'form-control datepicker-base', 'id'=>'draft_item_'.$booking_draft_item->id.'_end_date')) }}

                </div>


                @if(in_array($booking_draft_item->draft_type_id, [24, 26, 30, 31, 32, 33, 34, 35, 36, 37, 41]))
                    <div class="form-group col-6 col-sm-6 col-md-3 col-lg-3">
                        <div class="input-group">
                            <select class="custom-select" name="draft_item[{{$booking_draft_item->id}}][adult]" id="draft_item_{{$booking_draft_item->id }}_adult">
                                <option value="">0. T</option>
                                {!!  HTMLHelper::getRangeOptions($booking_draft_item->adult, 10, ' T.') !!}
                            </select>
                            {{ Form::text('draft_item['.$booking_draft_item->id.'][price_adult]', $booking_draft_item->price_adult,  array('placeholder'=>__('Preis in €'), 'class'=>'form-control', 'id'=>'draft_item_'.$booking_draft_item->id.'_price_adult',)) }}
                            <div class="input-group-prepend d-md-none d-lg-block">
                                <span class="input-group-text">€</span>
                            </div>
                        </div>
                    </div>

                    <div class="form-group col-6 col-sm-6 col-md-3 col-lg-3">
                        <div class="input-group">
                            <select class="custom-select"  name="draft_item[{{$booking_draft_item->id}}][children]" id="draft_item_{{$booking_draft_item->id}}_children">
                                <option value="">0. K</option>
                                {!!  HTMLHelper::getRangeOptions($booking_draft_item->children, 10, ' K.') !!}
                            </select>
                            {{ Form::text('draft_item['.$booking_draft_item->id.'][price_children]', $booking_draft_item->price_children,  array('placeholder'=>__('Preis in €'), 'class'=>'form-control', 'id'=>'draft_item_'.$booking_draft_item->id.'_price_children')) }}
                            <div class="input-group-prepend d-md-none d-lg-block">
                                <span class="input-group-text">€</span>
                            </div>
                        </div>
                    </div>
                @endif



                @if(in_array($booking_draft_item->draft_type_id, [36, 37]))
                    <div class="form-group col-3 col-sm-3 col-md-2 col-lg-2">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span class="input-group-text">A:</span>
                            </div>
                            {{ Form::text('draft_item['.$booking_draft_item->id.'][days_duration]', $booking_draft_item->days_duration,  array('placeholder'=>__('Anzahl Tage'), 'class'=>'form-control', 'id'=>'draft_item_'.$booking_draft_item->id.'_days_duration',)) }}
                        </div>
                    </div>
                    <div class="form-group col-5 col-sm-6 col-md-8">
                @else
                    <div class="form-group col-8 col-sm-9 col-md-10">
                @endif
                     {{ Form::textarea('draft_item['.$booking_draft_item->id.'][service]', $booking_draft_item->service,  array('placeholder'=>__('Leistungen'), 'class'=>'form-control autoExpand', 'id'=>'draft_item_'.$booking_draft_item->id.'_service', 'rows'=>'1', 'data-min-rows'=>'1')) }}
                </div>

                <div class="form-group col-4 col-sm-3 col-md-2">
                    <div class="text-right mt-2 float-right">
                        <a class="text-danger" href="{{ route('booking_draft_item_delete', [$booking_draft_item->id]) }}"  onclick="return confirm('{{__('Wirklich löschen?')}}');"><i class="fa fa-trash-alt"></i></a>
                    </div>
                    <label class="custom-control custom-checkbox mt-2" style="margin-right: 20px;">
                        {!! Form::checkbox('draft_item['.$booking_draft_item->id.'][in_pdf]', 1, $booking_draft_item->in_pdf, ['class'=>'custom-control-input']) !!}
                        <span class="custom-control-label">{{__('in PDF')}}</span>
                    </label>
                </div>

                @if(in_array($booking_draft_item->draft_type_id, [38, 39,40]))
                    <div class="form-group col-6">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span class="input-group-text">€ </span>
                            </div>
                            {{ Form::text('draft_item['.$booking_draft_item->id.'][price]', $booking_draft_item->price,  array('placeholder'=>__('Preis in €'), 'class'=>'form-control', 'id'=>'draft_item_'.$booking_draft_item->id.'_price',)) }}
                        </div>
                    </div>
                        @if(in_array($booking_draft_item->draft_type_id, [38]))

                        <div class="form-group col-6">
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <span class="input-group-text">A:</span>
                                </div>
                                {{ Form::text('draft_item['.$booking_draft_item->id.'][days_duration]', $booking_draft_item->days_duration,  array('placeholder'=>__('Anzahl Tage'), 'class'=>'form-control', 'id'=>'draft_item_'.$booking_draft_item->id.'_days_duration',)) }}
                            </div>
                        </div>
                        @endif

                    @endif
            </div>
        </div>
        @endforeach
        </div>
    @endif

        <div class="text-right">
            <button type="submit" name="action" value="addItemDown" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i> Neue Leistung hinzufügen <i class="fa fa-arrow-down"></i></button>
        </div>

        <div class="text-left mt-3">
        <button type="submit" name="action" value="saveAll" class="btn btn-submit">{{ __('save changes') }}</button>&nbsp;
        <a href="{{route('bookings')}}" class="btn btn-default">{{ __('zur Übersicht') }}</a>
            <a href="{{ make_old_url('/index.php/booking/'.$booking->id.'/edit') }}" class="btn btn-default float-right">{{ __('zurück ins CRM v2') }}</a>

        </div>

    {!! Form::close() !!}









@endsection