<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->fewo_lodging)
            <tr>
                <th scope="row">{{$booking_files_count++}}</th>
                <td>
                    <a target="_blank" href="{{ route('customer_file_show', ['fewo_instruction_pdf', $booking->fewo_lodging->id, 'stream']) }}" class="badge badge-md badge-next">
                        <i class="fa fa-file-pdf mr-1"></i> {{\App\Services\BookingFewo::getFeWoInstructionPDFName($booking->fewo_lodging)}}
                    </a>
                </td>
                <td>
                    application/pdf
                </td>
                <td>-</td>
                <td>
                    <button data-target="{{ route('customer_file_show', ['fewo_instruction_pdf', $booking->fewo_lodging->id, 'stream']) }}" data-name="{{\App\Services\BookingFewo::getFeWoInstructionPDFName($booking->fewo_lodging)}}" 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

        @foreach(\App\Services\BookingFewo::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->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_fewo_mail_ajax')}}');
            $elem.data('target', $(this).data('target'));
            $elem.data('name', $(this).data('name'));
            ajax_object_action(event, $elem, callback_ajax_add_attachment);
        });

    });
</script>