<div class="table-responsive border-bottom mb-2">
    <table class="table table-striped table-sm" id="table-modal-lead-files">
        <thead>
        <tr>
            <th>#</th>
            <th>Datei</th>
            <th>Inhalt</th>
            <th>Datum</th>
            <th>&nbsp;</th>
        </tr>
        </thead>
        <tbody>
        @php($lead_files_count = 1)
              
        @foreach(\App\Services\Lead::contentFiles() as $content_file)
            @if($file = \App\Models\CMSContent::getModelBySlug($content_file))
                <tr>
                    <th scope="row">{{$lead_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($lead->lead_files)
            @foreach($lead->lead_files as $lead_file)
                <tr>
                    <th scope="row">{{$lead_files_count++}}</th>
                    <td>
                        <a target="_blank" href="{{ $lead_file->getURL() }}" class="badge badge-md badge-secondary">
                            <i class="{{$lead_file->getIconExt()}} mr-1"></i> {{ $lead_file->original_name }}
                        </a>
                    </td>
                    <td>
                        {{ $lead_file->mine }} | {{ $lead_file->formatBytes() }}
                    </td>
                    <td>{{\App\Services\Util::_format_date($lead_file->created_at, 'date')}}</td>
                    <td>
                        <button data-target="{{ $lead_file->getURL() }}" data-name="{{ $lead_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-lead-files [rel="tooltip"]').tooltip({trigger: "hover"});
        $('#table-modal-lead-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('lead_mail_ajax')}}');
            $elem.data('target', $(this).data('target'));
            $elem.data('name', $(this).data('name'));
            ajax_object_action(event, $elem, callback_ajax_add_attachment);
        });

    });
</script>