@extends('layouts.admin')

@section('title', 'Ajouter Frais de Livraison')
@section('page-title', 'Ajouter Frais de Livraison')

@section('content')
<div class="card">
    <div class="card-header bg-white">
        <h5 class="mb-0">Nouveau Frais de Livraison</h5>
    </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-fees.store') }}" method="POST">
            @csrf
            <div class="row">
                <div class="col-md-6 mb-3">
                    <label class="form-label">Pays *</label>
                    <select name="country" id="country" class="form-select @error('country') is-invalid @enderror" required>
                        <option value="">Sélectionnez un pays</option>
                        @foreach($countries as $countryName => $countryCode)
                            <option value="{{ $countryName }}" {{ old('country') == $countryName ? 'selected' : '' }}>
                                {{ $countryName }}
                            </option>
                        @endforeach
                    </select>
                    @error('country')<div class="invalid-feedback">{{ $message }}</div>@enderror
                </div>
                <div class="col-md-6 mb-3">
                    <label class="form-label">Ville (optionnel)</label>
                    <input type="text" name="city" class="form-control @error('city') is-invalid @enderror" value="{{ old('city') }}" placeholder="Laissez vide pour tout le pays">
                    @error('city')<div class="invalid-feedback">{{ $message }}</div>@enderror
                </div>
            </div>
            <div class="row">
                <div class="col-md-6 mb-3">
                    <label class="form-label">Quartier (optionnel)</label>
                    <input type="text" name="district" class="form-control @error('district') is-invalid @enderror" value="{{ old('district') }}" placeholder="Laissez vide pour toute la ville">
                    @error('district')<div class="invalid-feedback">{{ $message }}</div>@enderror
                </div>
                <div class="col-md-6 mb-3">
                    <label class="form-label">Frais de Livraison (XOF) *</label>
                    <input type="number" name="fee" class="form-control @error('fee') is-invalid @enderror" value="{{ old('fee') }}" min="0" step="0.01" required>
                    @error('fee')<div class="invalid-feedback">{{ $message }}</div>@enderror
                </div>
            </div>
            <div class="row">
                <div class="col-md-6 mb-3">
                    <label class="form-label">Montant minimum livraison gratuite (XOF)</label>
                    <input type="number" name="free_shipping_minimum" class="form-control @error('free_shipping_minimum') is-invalid @enderror" value="{{ old('free_shipping_minimum') }}" min="0" step="0.01" placeholder="Optionnel">
                    @error('free_shipping_minimum')<div class="invalid-feedback">{{ $message }}</div>@enderror
                </div>
                <div class="col-md-6 mb-3">
                    <label class="form-label">Jours estimés de livraison</label>
                    <input type="number" name="estimated_days" class="form-control @error('estimated_days') is-invalid @enderror" value="{{ old('estimated_days') }}" min="1" max="30" placeholder="Optionnel">
                    @error('estimated_days')<div class="invalid-feedback">{{ $message }}</div>@enderror
                </div>
            </div>
            <div class="mb-3">
                <div class="form-check form-switch">
                    <input class="form-check-input" type="checkbox" name="is_active" id="is_active" value="1" {{ old('is_active', true) ? 'checked' : '' }}>
                    <label class="form-check-label" for="is_active">Actif</label>
                </div>
            </div>
            <div class="d-flex gap-2">
                <button type="submit" class="btn btn-primary">
                    <i class="bi bi-check-circle me-1"></i> Enregistrer
                </button>
                <a href="{{ route('admin.shipping-fees.index') }}" class="btn btn-secondary">
                    <i class="bi bi-x-circle me-1"></i> Annuler
                </a>
            </div>
        </form>
    </div>
</div>
@endsection