@extends('layouts.app')

@section('content')
<div class="container">
    <h1 class="mb-4">Exhibits</h1>

    <a href="{{ route('exhibits.create') }}" class="btn btn-primary mb-3">Add New Exhibit</a>

    @if(session('success'))
        <div class="alert alert-success">{{ session('success') }}</div>
    @endif

    <table class="table table-bordered">
        <thead class="table-dark">
            <tr>
                <th>ID</th>
                <th>Gallery</th>
                <th>Name</th>
                <th>Language</th>
                <th>Icon</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            @foreach ($exhibits as $exhibit)
                <tr>
                    <td>{{ $exhibit->id }}</td>
                    <td>{{ $exhibit->gallery->gallery_name }}</td>
                    <td>{{ $exhibit->exhibit_name }}</td>
                    <td>{{ $exhibit->language }}</td>
                    <td>
                        @if($exhibit->exhibit_icon_path)
                            <img src="{{ asset('storage/' . $exhibit->exhibit_icon_path) }}" width="50">
                        @else
                            N/A
                        @endif
                    </td>
                    <td>
                        <a href="{{ route('exhibits.edit', $exhibit->id) }}" class="btn btn-warning btn-sm">Edit</a>
                        <form action="{{ route('exhibits.destroy', $exhibit->id) }}" method="POST" style="display:inline;">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Delete this exhibit?');">Delete</button>
                        </form>
                    </td>
                </tr>
            @endforeach
        </tbody>
    </table>
</div>
@endsection
