@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">Edit Shipping Rate for {{ $zone->name }}</h3>
                    <div class="card-tools">
                        <a href="{{ route('admin.shipping.zones.rates.index', $zone) }}" class="btn btn-default btn-sm">
                            <i class="fas fa-arrow-left"></i> Back to Rates
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    @if($errors->any())
                        <div class="alert alert-danger">
                            <ul class="mb-0">
                                @foreach($errors->all() as $error)
                                    <li>{{ $error }}</li>
                                @endforeach
                            </ul>
                        </div>
                    @endif

                    <form action="{{ route('admin.shipping.zones.rates.update', [$zone, $rate]) }}" method="POST">
                        @csrf
                        @method('PUT')
                        
                        <div class="form-group">
                            <label for="service">Service Code</label>
                            <input type="text" name="service" id="service" class="form-control @error('service') is-invalid @enderror" value="{{ old('service', $rate->service) }}" required>
                        </div>

                        <div class="form-group">
                            <label for="service_name">Service Name</label>
                            <input type="text" name="service_name" id="service_name" class="form-control @error('service_name') is-invalid @enderror" value="{{ old('service_name', $rate->service_name) }}" required>
                            <small class="form-text text-muted">Display name (e.g., "Standard Shipping (3-5 days)")</small>
                        </div>

                        <div class="form-group">
                            <label for="amount">Amount ($)</label>
                            <input type="number" name="amount" id="amount" class="form-control @error('amount') is-invalid @enderror" value="{{ old('amount', $rate->amount) }}" step="0.01" min="0" required>
                        </div>

                        <div class="form-group">
                            <label for="delivery_days">Delivery Days</label>
                            <input type="text" name="delivery_days" id="delivery_days" class="form-control @error('delivery_days') is-invalid @enderror" value="{{ old('delivery_days', $rate->delivery_days) }}" required>
                            <small class="form-text text-muted">Format: "3-5" or "1-2"</small>
                        </div>

                        <div class="form-group">
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" name="is_active" id="is_active" value="1" {{ old('is_active', $rate->is_active) ? 'checked' : '' }}>
                                <label class="form-check-label" for="is_active">
                                    Active
                                </label>
                            </div>
                        </div>

                        <div class="form-group">
                            <button type="submit" class="btn btn-primary">Update Rate</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection