@extends('layouts.admin')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center mb-4">
                    <h3 class="card-title">Shipping Rates for {{ $zone->name }} ({{ $zone->code }})</h3>
                    <div class="card-tools">
                        <a href="{{ route('admin.shipping.zones.index') }}" class="btn btn-default btn-sm mr-2">
                            <i class="fas fa-arrow-left"></i> Back to Zones
                        </a>
                        <a href="{{ route('admin.shipping.zones.rates.create', $zone) }}" class="btn btn-primary btn-sm">
                            <i class="fas fa-plus"></i> Add New Rate
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    @if(session('success'))
                        <div class="alert alert-success">{{ session('success') }}</div>
                    @endif

                    <table class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Service</th>
                                <th>Service Name</th>
                                <th>Amount</th>
                                <th>Delivery Days</th>
                                <th>Status</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse($rates as $rate)
                                <tr>
                                    <td>{{ $rate->id }}</td>
                                    <td>{{ $rate->service }}</td>
                                    <td>{{ $rate->service_name }}</td>
                                    <td>${{ number_format($rate->amount, 2) }}</td>
                                    <td>{{ $rate->delivery_days }}</td>
                                    <td>
                                        @if($rate->is_active)
                                            <span class="badge bg-success">Active</span>
                                        @else
                                            <span class="badge bg-danger">Inactive</span>
                                        @endif
                                    </td>
                                    <td>
                                        <a href="{{ route('admin.shipping.zones.rates.edit', [$zone, $rate]) }}" class="btn btn-primary btn-sm">
                                            <i class="fas fa-edit"></i> Edit
                                        </a>
                                        <form action="{{ route('admin.shipping.zones.rates.destroy', [$zone, $rate]) }}" method="POST" class="d-inline">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure you want to delete this rate?')">
                                                <i class="fas fa-trash"></i> Delete
                                            </button>
                                        </form>
                                    </td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="7" class="text-center">No shipping rates found for this zone.</td>
                                </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection