<div class="table-responsive border-bottom mb-2">
    <table class="table table-striped table-sm" id="table-modal-booking-files">
        <thead>
        <tr>
            <th>#</th>
            <th>Datei</th>
            <th>Inhalt</th>
            <th>Datum</th>
            <th>&nbsp;</th>
        </tr>
        </thead>
        <tbody>
        @php($booking_files_count = 1)

        @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>
                        GB: {{ \App\Services\Util::_number_format($booking_application->total)}} &euro;
                    </td>
                    <td>{{\App\Services\Util::_format_date($booking_application->updated_at, 'date')}}</td>
                    <td>
                        <button data-target="{{ route('customer_file_show', ['booking_application', $booking_application->id, true]) }}" data-name="Reiseanmeldung.pdf" class="btn btn-xs btn-primary add-file-to-attachment add-file-to-attachment"
                           title="als Anhang hinzufügen" data-placement="left" rel="tooltip">
                            <i class="fa fa-cloud-download-alt"></i>
                        </button>
                    </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>
                        GP: {{ \App\Services\Util::_number_format($booking_confirmation->total)}} &euro; |
                        AZ: {{ \App\Services\Util::_number_format($booking_confirmation->deposit)}} &euro; |
                        RE: {{ \App\Services\Util::_number_format($booking_confirmation->final_payment)}} &euro;
                    </td>
                    <td>{{\App\Services\Util::_format_date($booking_confirmation->updated_at, 'date')}}</td>
                    <td>
                        <button data-target="{{ route('customer_file_show', ['booking_confirmation', $booking_confirmation->id]) }}" data-name="Reisebestätigung.pdf" class="btn btn-xs btn-primary add-file-to-attachment"
                           title="als Anhang hinzufügen" data-placement="left" rel="tooltip">
                            <i class="fa fa-cloud-download-alt"></i>
                        </button>
                    </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>
                        Stornobetrag: {{ \App\Services\Util::_number_format($booking_storno->total)}} &euro;
                    </td>
                    <td>{{\App\Services\Util::_format_date($booking_storno->updated_at, 'date')}}</td>
                    <td>
                        <button data-target="{{ route('customer_file_show', ['booking_storno', $booking_storno->id]) }}" data-name="Stornobestätigung.pdf" class="btn btn-xs btn-primary add-file-to-attachment"
                           title="als Anhang hinzufügen" data-placement="left" rel="tooltip">
                            <i class="fa fa-cloud-download-alt"></i>
                        </button>
                    </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>
                        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>
                        <button data-target="{{ route('customer_file_show', ['coupon', $coupon->id]) }}" data-name="Gutschein_{{$coupon->number}}.pdf" class="btn btn-xs btn-primary add-file-to-attachment"
                           title="als Anhang hinzufügen" data-placement="left" rel="tooltip">
                            <i class="fa fa-cloud-download-alt"></i>
                        </button>
                    </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>
                        <button data-target="{{ route('customer_file_show', ['booking_vouchers', $booking_voucher->id]) }}" data-name="Voucher-ID_{{$booking_voucher->id}}.pdf" class="btn btn-xs btn-primary add-file-to-attachment"
                           title="als Anhang hinzufügen" data-placement="left" rel="tooltip">
                            <i class="fa fa-cloud-download-alt"></i>
                        </button>
                    </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>
                        <button data-target="{{ route('customer_file_show', ['insurance_certificates', $insurance_certificate->id]) }}" data-name="Sicherungsschein-Nr-{{$insurance_certificate->internal_id}}.pdf" class="btn btn-xs btn-primary add-file-to-attachment"
                           title="als Anhang hinzufügen" data-placement="left" rel="tooltip">
                            <i class="fa fa-cloud-download-alt"></i>
                        </button>
                    </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>
                        {{ $file->formatBytes() }}
                    </td>
                    <td>{{\App\Services\Util::_format_date($file->created_at, 'date')}}</td>
                    <td>
                        <button data-target="{{ $file->getURL() }}" data-name="{{ $file->name }}" class="btn btn-xs btn-primary add-file-to-attachment"
                                title="als Anhang hinzufügen" data-placement="left" rel="tooltip">
                            <i class="fa fa-cloud-download-alt"></i>
                        </button>
                    </td>
                </tr>
            @endif
        @endforeach
        @if($booking->travel_country)
        @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>
                            {{ $general_files->mine }} | {{ $general_files->formatBytes() }}
                        </td>
                        <td>{{\App\Services\Util::_format_date($general_files->created_at, 'date')}}</td>
                        <td>
                            <button data-target="{{ $general_files->getURL() }}" data-name="{{ $general_files->original_name }}" class="btn btn-xs btn-primary add-file-to-attachment"
                                    title="als Anhang hinzufügen" data-placement="left" rel="tooltip">
                                <i class="fa fa-cloud-download-alt"></i>
                            </button>
                        </td>
                    </tr>
                @endforeach
            @endif
        @endforeach
        @endif

        @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>
                        <button data-target="{{ $PassolutionPDF['url'] }}" data-name="{{$PassolutionPDF['filename']}}" class="btn btn-xs btn-primary add-file-to-attachment"
                                title="als Anhang hinzufügen" data-placement="left" rel="tooltip">
                            <i class="fa fa-cloud-download-alt"></i>
                        </button>
                    </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>
                        {{ $booking_file->mine }} | {{ $booking_file->formatBytes() }}
                    </td>
                    <td>{{\App\Services\Util::_format_date($booking_file->created_at, 'date')}}</td>
                    <td>
                        <button data-target="{{ $booking_file->getURL() }}" data-name="{{ $booking_file->original_name }}" class="btn btn-xs btn-primary add-file-to-attachment"
                           title="als Anhang hinzufügen" data-placement="left" rel="tooltip">
                            <i class="fa fa-cloud-download-alt"></i>
                        </button>
                    </td>
                </tr>
            @endforeach
        @endif
        </tbody>
    </table>

</div>
<script type="text/javascript">
    $(document).ready(function() {
        $('#table-modal-booking-files [rel="tooltip"]').tooltip({trigger: "hover"});
        $('#table-modal-booking-files .add-file-to-attachment').on('click', function (event) {
            var $elem = $('<div/>');
            $elem.data('action', 'add_attachment');
            $elem.data('id', 'new');
            $elem.data('url', '{{route('customer_mail_ajax')}}');
            $elem.data('target', $(this).data('target'));
            $elem.data('name', $(this).data('name'));
            ajax_object_action(event, $elem, callback_ajax_add_attachment);
        });

    });
</script>