@extends('admin.layouts.app')

@section('title', 'Data Wisata')
@section('page_title', 'Data Wisata')
@section('page_subtitle', 'Destinasi normal, AR, video, koordinat, dan media')

@section('content')
<div class="card soft-card">
    <div class="card-body">
        <div class="d-flex flex-column flex-md-row justify-content-between gap-3 mb-3">
            <form class="d-flex gap-2" method="GET">
                <input class="form-control" name="search" value="{{ request('search') }}" placeholder="Cari wisata atau lokasi">
                <button class="btn btn-outline-ocean" type="submit"><i class="bi bi-search"></i></button>
            </form>
            <a class="btn btn-nature" href="{{ route('admin.wisata.create') }}"><i class="bi bi-plus-lg me-1"></i>Tambah Wisata</a>
        </div>
        <div class="table-responsive">
            <table class="table table-hover" id="wisataTable">
                <thead><tr><th>Wisata</th><th>Kategori</th><th>Lokasi</th><th>Rating</th><th>Tipe</th><th class="text-end">Aksi</th></tr></thead>
                <tbody>
                @forelse($wisatas as $wisata)
                    <tr>
                        <td>
                            <div class="d-flex align-items-center gap-3">
                                <img class="img-fluid object-thumb" src="{{ $wisata->image_url }}" alt="{{ $wisata->title }}">
                                <div><div class="fw-semibold">{{ $wisata->title }}</div><small class="text-muted">{{ $wisata->distance ?: 'Jarak belum diisi' }}</small></div>
                            </div>
                        </td>
                        <td>{{ $wisata->kategori?->nama }}</td>
                        <td>{{ $wisata->location }}</td>
                        <td>{{ $wisata->rating_label }}</td>
                        <td>
                            <span class="badge text-bg-ocean">Normal</span>
                            @if($wisata->model_path)<span class="badge text-bg-info">AR</span>@endif
                            @if($wisata->is_video)<span class="badge text-bg-dark">Video</span>@endif
                        </td>
                        <td class="text-end">
                            <a class="btn btn-sm btn-outline-primary" href="{{ route('admin.wisata.show', $wisata) }}"><i class="bi bi-eye"></i></a>
                            <a class="btn btn-sm btn-outline-ocean" href="{{ route('admin.wisata.edit', $wisata) }}"><i class="bi bi-pencil"></i></a>
                            <form class="d-inline" method="POST" action="{{ route('admin.wisata.destroy', $wisata) }}" data-confirm="Hapus data wisata dan semua medianya?">
                                @csrf @method('DELETE')
                                <button class="btn btn-sm btn-outline-danger" type="submit"><i class="bi bi-trash"></i></button>
                            </form>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="6" class="text-center text-muted py-4">Belum ada data wisata.</td></tr>
                @endforelse
                </tbody>
            </table>
        </div>
        {{ $wisatas->links() }}
    </div>
</div>
@endsection

@push('scripts')
<script>
new DataTable('#wisataTable', { paging: false, searching: false, info: false, responsive: true });
</script>
@endpush
