@extends('layouts.app-shell')
@section('title', 'Services')
@section('sidebar')
    @include('admin._sidebar')
@endsection
@section('bottomnav')
    <a href="{{ route('admin.dashboard') }}" class="{{ request()->routeIs('admin.dashboard*') ? 'active' : '' }}"><x-icon name="home" :size="20" /><span>Home</span></a>
    <a href="{{ route('admin.bookings') }}" class="{{ request()->routeIs('admin.bookings*') ? 'active' : '' }}"><x-icon name="bookings" :size="20" /><span>Subs</span></a>
    <a href="{{ route('admin.partners') }}" class="{{ request()->routeIs('admin.partners*') ? 'active' : '' }}"><x-icon name="profile" :size="20" /><span>Partners</span></a>
    <a href="{{ route('admin.services.index') }}" class="{{ request()->routeIs('admin.services*') ? 'active' : '' }}"><x-icon name="services" :size="20" /><span>Catalogue</span></a>
@endsection

@section('content')
<div class="flex-between mb-3">
    <div>
        <h2 style="font-size: 22px; font-weight: 700;">All services</h2>
        <p class="muted" style="font-size: 13px;">Manage the catalogue shown to customers.</p>
    </div>
    <a href="{{ route('admin.services.create') }}" class="btn btn-primary"><x-icon name="plus" :size="14" /> New service</a>
</div>

<x-admin-filter :searchPlaceholder="'Search services by name or slug'" />

<div class="panel">
    <div class="panel-head">
        <h3>{{ $services->total() }} service{{ $services->total() === 1 ? '' : 's' }}</h3>
    </div>
    <div class="table-wrap">
        <table class="table">
            <thead>
                <tr>
                    <th></th>
                    <th>Name</th>
                    <th>Category</th>
                    <th>Price</th>
                    <th>Featured</th>
                    <th>Status</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @forelse($services as $s)
                    <tr>
                        <td data-label="Thumb">
                            <div class="row-thumb">
                                @if($s->image && file_exists(storage_path('app/public/' . $s->image)))
                                    <img src="{{ asset('storage/' . $s->image) }}" alt="">
                                @else🛠@endif
                            </div>
                        </td>
                        <td data-label="Name">
                            <strong>{{ $s->name }}</strong>
                            <div class="muted" style="font-size: 11.5px;">{{ $s->slug }}</div>
                        </td>
                        <td data-label="Category">{{ $s->category->name ?? '—' }}</td>
                        <td data-label="Price">
                            <strong>₹{{ number_format($s->price_rupees, 0) }}</strong>
                            @if($s->original_price_paise)<span class="muted" style="text-decoration: line-through; margin-left: 4px;">₹{{ number_format($s->original_rupees, 0) }}</span>@endif
                        </td>
                        <td data-label="Featured">{!! $s->is_featured ? '<span class="pill pill-gold">featured</span>' : '<span class="muted">—</span>' !!}</td>
                        <td data-label="Status">{!! $s->is_active ? '<span class="pill pill-green">active</span>' : '<span class="pill pill-grey">off</span>' !!}</td>
                        <td data-label="">
                            <a href="{{ route('admin.services.edit', $s) }}" class="ic-btn" title="Edit"><x-icon name="edit" :size="14" /></a>
                            <form method="POST" action="{{ route('admin.services.destroy', $s) }}" style="display:inline" onsubmit="return confirm('Delete this service?');">
                                @csrf @method('DELETE')
                                <button class="ic-btn red" title="Delete"><x-icon name="trash" :size="14" /></button>
                            </form>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="7"><div class="empty">No services yet. <a href="{{ route('admin.services.create') }}" style="color: var(--bfk-primary); font-weight: 600;">Add your first service →</a></div></td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>

<div class="mt-3">{{ $services->appends(request()->query())->links() }}</div>

@endsection
