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

        @php($lead_files_count = 1)
        <div class="card-body row">
            <div class="table-responsive" id="lead_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>
                   
                        @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>
                                    <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

                    @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>
                                    <a href="{{ $lead_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('lead_delete', [$lead_file->id, 'lead_files']) }}"  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
            <button type="button" class="btn btn-sm btn-primary" data-toggle="modal"
                    data-target="#modals-load-content"
                    data-id="new-file"
                    data-model="LeadFile"
                    data-action="modal-upload-lead-file"
                    data-url=""
                    data-redirect="back"
                    data-lead_id="{{$lead->id}}"
                    data-route="{{ route('lead_mail_modal_load') }}"><i class="ion ion-md-cloud-upload"></i>&nbsp;Datei hinzufügen</button>
            </div>
        </div>
    </div>
</div>

