@extends('layouts.app')

@section('title', 'Resources - NGBVD')

@section('content')
<div class="ngbvd-page-header mb-3">
    <div>
        <span class="ngbvd-kicker">Resource Library</span>
        <h2 class="ngbvd-page-title">Upload Resources</h2>
        <p class="ngbvd-page-subtitle">Manage public and internal GBV resources, documents and evidence material.</p>
    </div>
    <button class="btn ngbvd-btn-primary" data-toggle="modal" data-target="#newresource"><i class="ti-upload"></i> Upload Resource</button>
</div>

@include('messages.index')

<div class="card ngbvd-table-card">
    <div class="card-block">
        <div class="ngbvd-table-toolbar">
            <div>
                <h5 class="mb-1">Resource Register</h5>
                <small class="text-muted">Search, preview, download or delete uploaded resources.</small>
            </div>
        </div>
        <div class="table-responsive">
            <table class="table table-hover ngbvd-modern-table" data-datatable="true">
                <thead>
                    <tr>
                        <th>No.</th>
                        <th>Resource Name</th>
                        <th>Category</th>
                        <th>Preview / Download</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($resources as $resource)
                        <tr>
                            <td>{{ $loop->iteration }}</td>
                            <td><strong>{{ $resource->name }}</strong></td>
                            <td><span class="ngbvd-badge ngbvd-badge-muted">{{ $resource->category }}</span></td>
                            <td>
                                @if (in_array(strtolower(pathinfo($resource->name, PATHINFO_EXTENSION)), ['jpg', 'jpeg', 'png', 'gif']))
                                    <a href="{{ url('resource/downloadfile/' . encrypt($resource->id)) }}" target="_blank">
                                        <img src="{{ url('resource/downloadfile/' . encrypt($resource->id)) }}" alt="{{ $resource->name }}" style="max-width: 90px; max-height: 70px; border-radius:12px; box-shadow:0 6px 15px rgba(15,23,42,.12);">
                                    </a>
                                @else
                                    <a href="{{ url('resource/downloadfile/' . encrypt($resource->id)) }}" class="ngbvd-action-btn" target="_blank"><i class="ti-download"></i> Download</a>
                                @endif
                            </td>
                            <td>
                                <a href="{{ url('/resource/deleteevidence/'.base64_encode(base64_encode($resource->id))) }}" onclick="return confirm('Are you sure you want to delete this resource?')" class="btn btn-sm btn-outline-danger"><i class="ti-trash"></i> Delete</a>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
</div>

@include('resources.index_resource')
@endsection
