@extends('layouts.admin')

@section('title', 'Shipping Methods')

@section('content')
<div class="admin-page-header">
    <h1>Shipping Methods</h1>
    @can('shipping-methods.create')
    <a href="{{ route('admin.shipping-methods.create') }}" class="admin-btn-primary">
        <i class="bi bi-plus"></i> Add Shipping Method
    </a>
    @endcan
</div>

<div class="admin-card">
    <div class="card-body">
        @if(isset($shippingMethods) && $shippingMethods->count() > 0)
            <div class="table-responsive">
                <table class="admin-table table table-hover">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Code</th>
                            <th>Price</th>
                            <th>Cart Value</th>
                            <th>Estimated Days</th>
                            <th>Sort Order</th>
                            <th>Status</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($shippingMethods as $method)
                            <tr>
                                <td>
                                    <strong>{{ $method->name }}</strong>
                                    @if($method->description)
                                        <br><small class="text-muted">{{ Str::limit($method->description, 50) }}</small>
                                    @endif
                                </td>
                                <td><code>{{ $method->code }}</code></td>
                                <td>₹{{ number_format($method->price, 2) }}</td>
                                <td>
                                    @if($method->cart_value)
                                        ₹{{ number_format($method->cart_value, 2) }}
                                    @else
                                        <span class="text-muted">—</span>
                                    @endif
                                </td>
                                <td>{{ $method->estimated_days }}</td>
                                <td>{{ $method->sort_order }}</td>
                                <td>
                                    <span class="badge-modern {{ $method->is_active ? 'badge-modern-success' : 'badge-modern-danger' }}">
                                        {{ $method->is_active ? 'Active' : 'Inactive' }}
                                    </span>
                                </td>
                                <td>
                                    <div class="d-flex gap-2">
                                        @can('shipping-methods.update')
                                        <a href="{{ route('admin.shipping-methods.edit', $method->id) }}" 
                                           class="admin-action-btn admin-action-btn-sm admin-btn-primary"
                                           title="Edit">
                                            <i class="bi bi-pencil"></i>
                                        </a>
                                        @endcan
                                        @can('shipping-methods.delete')
                                        <form action="{{ route('admin.shipping-methods.destroy', $method->id) }}" 
                                              method="POST" 
                                              class="d-inline" 
                                              onsubmit="return confirm('Are you sure you want to delete this shipping method?')">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" 
                                                    class="admin-action-btn admin-action-btn-sm"
                                                    style="background: #ef4444; height: -webkit-fill-available; color: white;"
                                                    title="Delete">
                                                <i class="bi bi-trash"></i>
                                            </button>
                                        </form>
                                        @endcan
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        @else
            <div class="admin-empty-state">
                <i class="bi bi-truck"></i>
                <h3>No Shipping Methods Found</h3>
                @can('shipping-methods.create')
                <p>Get started by creating your first shipping method.</p>
                <a href="{{ route('admin.shipping-methods.create') }}" class="admin-btn-primary">
                    <i class="bi bi-plus"></i> Add Shipping Method
                </a>
                @endcan
            </div>
        @endif
    </div>
</div>
@endsection
