<!-- Files -->
<div class="card mb-2">
    <h6 class="card-header  bg-primary text-white py-2" data-toggle="collapse" data-target="#collapseBookingFiles" aria-expanded="false" aria-controls="collapseBookingFiles">
        <strong style="line-height: 1.6em">PDF Dateien</strong>
    </h6>
    <div class="collapse" id="collapseBookingFiles">

        @php($booking_files_count = 1)
        <div class="card-body row">
            <div class="table-responsive" id="booking_files_table">
                <table class="table table-striped table-sm">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>Datei</th>
                        <th>Inhalt</th>
                        <th>Datum</th>
                        <th>&nbsp;</th>
                    </tr>
                    </thead>
                    <tbody>

                    @if($booking->booking_applications)
                        @foreach($booking->booking_applications as $booking_application)
                            <tr>
                                <th scope="row">{{$booking_files_count++}}</th>
                                <td>
                                    <a href="{{ route('customer_file_show', ['booking_application', $booking_application->id]) }}" target="_blank" class="badge badge-md badge-primary">
                                        <i class="fa fa-file-pdf mr-1"></i> Reiseanmeldung
                                    </a>
                                </td>
                                <td>
                                    Reise |
                                    Gesamtpreis: {{ \App\Services\Util::_number_format($booking_application->total)}} &euro;
                                </td>
                                <td>{{\App\Services\Util::_format_date($booking_application->updated_at, 'date')}}</td>
                                <td>
                                    <a href="{{ route('customer_file_show', ['booking_application', $booking_application->id, true]) }}" class="btn btn-xs btn-default"
                                       title="Download" data-placement="left" rel="tooltip">
                                        <i class="fa fa-download"></i>
                                    </a>
                                </td>
                            </tr>
                        @endforeach
                    @endif

                    @if($booking->booking_confirmations)
                        @foreach($booking->booking_confirmations as $booking_confirmation)
                            <tr>
                                <th scope="row">{{$booking_files_count++}}</th>
                                <td>
                                    <a href="{{ route('customer_file_show', ['booking_confirmation', $booking_confirmation->id]) }}" target="_blank" class="badge badge-md badge-success">
                                        <i class="fa fa-file-pdf mr-1"></i> Reisebestätigung
                                    </a>
                                </td>
                                <td>
                                    Reise |
                                    Gesamtpreis: {{ \App\Services\Util::_number_format($booking_confirmation->total)}} &euro; |
                                    Anzahlung: {{ \App\Services\Util::_number_format($booking_confirmation->deposit)}} &euro; |
                                    Restzahlung: {{ \App\Services\Util::_number_format($booking_confirmation->final_payment)}} &euro;
                                </td>
                                <td>{{\App\Services\Util::_format_date($booking_confirmation->updated_at, 'date')}}</td>
                                <td>
                                    <a href="{{ route('customer_file_show', ['booking_confirmation', $booking_confirmation->id, true]) }}" class="btn btn-xs btn-default"
                                       title="Download" data-placement="left" rel="tooltip">
                                        <i class="fa fa-download"></i>
                                    </a>
                                </td>
                            </tr>
                        @endforeach
                    @endif

                    @if($booking->booking_stornos)
                        @foreach($booking->booking_stornos as $booking_storno)
                            <tr>
                                <th scope="row">{{$booking_files_count++}}</th>
                                <td>
                                    <a href="{{ route('customer_file_show', ['booking_storno', $booking_storno->id]) }}" target="_blank" class="badge badge-md badge-danger">
                                        <i class="fa fa-file-pdf mr-1"></i> Stornobestätigung
                                    </a>
                                </td>
                                <td>
                                    Storno | Betrag: {{ \App\Services\Util::_number_format($booking_storno->total)}} &euro;
                                </td>
                                <td>{{\App\Services\Util::_format_date($booking_storno->updated_at, 'date')}}</td>
                                <td>
                                    <a href="{{ route('customer_file_show', ['booking_storno', $booking_storno->id, true]) }}" class="btn btn-xs btn-default"
                                       title="Download" data-placement="left" rel="tooltip">
                                        <i class="fa fa-download"></i>
                                    </a>
                                </td>
                            </tr>
                        @endforeach
                    @endif

                    @if($booking->coupons)
                        @foreach($booking->coupons as $coupon)
                            <tr>
                                <th scope="row">{{$booking_files_count++}}</th>
                                <td>
                                    <a href="{{ route('customer_file_show', ['coupon', $coupon->id]) }}" target="_blank" class="badge badge-md badge-warning">
                                        <i class="fa fa-file-pdf mr-1"></i> Gutschein {{$coupon->number}}
                                    </a>
                                </td>
                                <td>Gutschein |
                                    Wert: {{ \App\Services\Util::_number_format($coupon->value)}} &euro; |
                                    bis: {{\App\Services\Util::_format_date($coupon->valid_date, 'date')}} |
                                    @if($coupon->is_redeemed) <i class="fa fa-check-circle text-success"></i> {{\App\Services\Util::_format_date($coupon->redeem_date, 'date')}}  @else <i class="fa fa-times-circle text-danger"></i>  @endif
                                </td>
                                <td>{{\App\Services\Util::_format_date($coupon->issue_date, 'date')}}</td>
                                <td>
                                    <a href="{{ route('customer_file_show', ['coupon', $coupon->id, true]) }}" class="btn btn-xs btn-default"
                                       title="Download" data-placement="left" rel="tooltip">
                                        <i class="fa fa-download"></i>
                                    </a>
                                </td>
                            </tr>
                        @endforeach
                    @endif

                    @if($booking->booking_vouchers)
                        @foreach($booking->booking_vouchers as $booking_voucher)
                            <tr>
                                <th scope="row">{{$booking_files_count++}}</th>
                                <td>
                                    <a href="{{ route('customer_file_show', ['booking_voucher', $booking_voucher->id]) }}" target="_blank" class="badge badge-md badge-dark">
                                        <i class="fa fa-file-pdf mr-1"></i> Voucher-ID {{$booking_voucher->id}}
                                    </a>
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                                <td>{{\App\Services\Util::_format_date($booking_voucher->updated_at, 'date')}}</td>
                                <td>
                                    <a href="{{ route('customer_file_show', ['booking_vouchers', $booking_voucher->id, true]) }}" class="btn btn-xs btn-default"
                                       title="Download" data-placement="left" rel="tooltip">
                                        <i class="fa fa-download"></i>
                                    </a>
                                </td>
                            </tr>
                        @endforeach
                    @endif

                    @if($booking->insurance_certificates)
                        @foreach($booking->insurance_certificates as $insurance_certificate)
                            <tr>
                                <th scope="row">{{$booking_files_count++}}</th>
                                <td>
                                    <a href="{{ route('customer_file_show', ['insurance_certificate', $insurance_certificate->id]) }}" target="_blank" class="badge badge-md badge-next">
                                        <i class="fa fa-file-pdf mr-1"></i> Sicherungsschein Nr. {{$insurance_certificate->internal_id}}
                                    </a>
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                                <td>{{\App\Services\Util::_format_date($insurance_certificate->updated_at, 'date')}}</td>
                                <td>
                                    <a href="{{ route('customer_file_show', ['insurance_certificates', $insurance_certificate->id, true]) }}" class="btn btn-xs btn-default"
                                       title="Download" data-placement="left" rel="tooltip">
                                        <i class="fa fa-download"></i>
                                    </a>
                                </td>
                            </tr>
                        @endforeach
                    @endif

                    @if($booking->travel_insurances)
                        @foreach($booking->travel_insurances as $travel_insurances)
                            <tr>
                                <th scope="row">{{$booking_files_count++}}</th>
                                <td>
                                    <i class="fa fa-info-circle mr-1"></i> Policennummer {{$travel_insurances->policy_number}}
                                </td>
                                <td>
                                    Gesamtprämie: {{ \App\Services\Util::_number_format($travel_insurances->premium)}} &euro;
                                </td>
                                <td>{{\App\Services\Util::_format_date($travel_insurances->updated_at, 'date')}}</td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                        @endforeach
                    @endif

                    @foreach(\App\Services\Booking::contentFiles() as $content_file)
                        @if($file = \App\Models\CMSContent::getModelBySlug($content_file))
                            <tr>
                                <th scope="row">{{$booking_files_count++}}</th>
                                <td>
                                    <a target="_blank" href="{{ $file->getURL() }}" class="badge badge-md badge-next">
                                        <i class="fa fa-file-pdf mr-1"></i> {{$file->name}}
                                    </a>
                                </td>
                                <td>
                                    @if(Auth::user()->isPermission('sua-st-em'))
                                     <a href="{{route('admin_settings_emails', ['settings'])}}">E-Mails</a> |
                                    @endif
                                    {{ $file->formatBytes() }}
                                </td>
                                <td>{{\App\Services\Util::_format_date($file->created_at, 'date')}}</td>
                                <td>
                                    <a href="{{ $file->getURL('download') }}" class="btn btn-xs btn-default"
                                       title="Download" data-placement="left" rel="tooltip">
                                        <i class="fa fa-download"></i>
                                    </a>
                                </td>
                            </tr>
                        @endif
                    @endforeach

                    @foreach($booking->travel_country->getContactLandsModels() as $TravelCountry)
                      @if($TravelCountry->stern_travel_country)
                      @foreach($TravelCountry->stern_travel_country->general_files as $general_files)
                          <tr>
                              <th scope="row">{{$booking_files_count++}}</th>
                              <td>
                                  <a target="_blank" href="{{ $general_files->getURL() }}" class="badge badge-md badge-info">
                                      <i class="{{$general_files->getIconExt()}} mr-1"></i> {{$general_files->original_name}}
                                  </a>
                              </td>
                              <td>
                                  @if(Auth::user()->isPermission('sua-st-co'))
                                  <a href="{{route('admin_settings_travel_country_detail', [$TravelCountry->stern_travel_country->id, 'data'])}}">{{$TravelCountry->stern_travel_country->name }}</a> |
                                  @endif
                                  {{ $general_files->mine }} | {{ $general_files->formatBytes() }}
                              </td>
                              <td>{{\App\Services\Util::_format_date($general_files->created_at, 'date')}}</td>
                              <td>
                                  <a href="{{ $general_files->getURL('download') }}" class="btn btn-xs btn-default"
                                     title="Download" data-placement="left" rel="tooltip">
                                      <i class="fa fa-download"></i>
                                  </a>
                              </td>
                          </tr>
                      @endforeach
                      @endif
                    @endforeach

                    @foreach($booking->getPassolutionPDF() as $PassolutionPDF)
                        @if($PassolutionPDF)
                            <tr>
                                <th scope="row">{{$booking_files_count++}}</th>
                                <td>
                                    <a target="_blank" href="{{ $PassolutionPDF['url'] }}" class="badge badge-md badge-next">
                                        <i class="fa fa-file-pdf mr-1"></i> {{$PassolutionPDF['filename']}}
                                    </a>
                                </td>
                                <td>
                                    Passolution |
                                    {{ \App\Services\Util::_formatBytes($PassolutionPDF['size']) }}
                                </td>
                                <td>{{\App\Services\Util::_format_date($PassolutionPDF['date'], 'date')}}</td>
                                <td>
                                    <a href="{{ $PassolutionPDF['url'] }}" class="btn btn-xs btn-default"
                                       title="Download" data-placement="left" rel="tooltip" download="">
                                        <i class="fa fa-download"></i>
                                    </a>
                                </td>
                            </tr>
                        @endif
                    @endforeach

                    @if($booking->booking_files)
                        @foreach($booking->booking_files as $booking_file)
                            <tr>
                                <th scope="row">{{$booking_files_count++}}</th>
                                <td>
                                    <a target="_blank" href="{{ $booking_file->getURL() }}" class="badge badge-md badge-secondary">
                                        <i class="{{$booking_file->getIconExt()}} mr-1"></i> {{$booking_file->original_name}}
                                    </a>
                                </td>
                                <td>
                                    hinzugefügt |
                                    {{ $booking_file->mine }} | {{ $booking_file->formatBytes() }}
                                </td>
                                <td>{{\App\Services\Util::_format_date($booking_file->created_at, 'date')}}</td>
                                <td>
                                    <a href="{{ $booking_file->getURL('download') }}" class="btn btn-xs btn-default"
                                       title="Download" data-placement="left" rel="tooltip">
                                        <i class="fa fa-download"></i>
                                    </a>
                                    <a class="ml-2 btn btn-xs btn-danger" href="{{ route('booking_delete', [$booking_file->id, 'booking_file']) }}"  onclick="return confirm('{{__('Wirklich löschen?')}}');"><i class="fa fa-trash-alt"></i></a>

                                </td>
                            </tr>
                        @endforeach
                    @endif
                    </tbody>
                </table>

            </div>

            <div class="text-right d-block w-100">
                @if(Auth::user()->isPermission('sua-st-em'))
                    <div class="float-left small">Allgemeine Dateien unter: <a href="{{route('admin_settings_emails', ['settings'])}}">Einstellungen -> E-Mails / Einstellungen</a></div>
                @endif
                @if(Auth::user()->isPermission('sua-st-co'))
                    <br><div class="float-left small">Landesspezifische Dateien unter: <a href="{{route('admin_settings_travel_country', [])}}">Einstellungen -> Reieseländer</a></div>
                @endif
                   <button type="button" class="btn btn-sm btn-primary" data-toggle="modal"
                    data-target="#modals-load-content"
                    data-id="new-file"
                    data-model="bookingFile"
                    data-action="modal-upload-booking-file"
                    data-url=""
                    data-redirect="back"
                    data-booking_id="{{$booking->id}}"
                    data-route="{{ route('booking_modal_load') }}"><i class="ion ion-md-cloud-upload"></i>&nbsp;Datei hinzufügen</button>
            </div>
        </div>
    </div>
</div>

