@php
    $defaultSaleChannelId = $customer['default_sale_channel_id'] ?? null;
    $preselectedDeliveryId = old('delivery_id');

    if (! $preselectedDeliveryId && $defaultSaleChannelId) {
        $match = collect($deliveries)->firstWhere('sale_channel_id', $defaultSaleChannelId);
        $preselectedDeliveryId = $match['id'] ?? null;
    }
@endphp

@foreach ($deliveries as $delivery)
    <div class="row">
        <div class="col-1">
            @include('components.form.radios.icheck', [
                'name' => 'delivery_id',
                'val' => $delivery['id'],
                'value' => $preselectedDeliveryId,
                'id' => 'delivery_' . $delivery['id'],
                'class' => 'delivery_mode' . ($delivery['at_house'] ? ' at_house' : ''),
            ])
        </div>
        <div class="col-11">
            <strong>{{ $delivery['name'] }} - Tarif appliqué {{ $delivery['sale_channel']['name'] }}</strong><br />
            {!! $delivery['sale_channel']['description'] !!}
        </div>
    </div>
@endforeach

{!! $errors->first('delivery_id', '<p class="text-danger"><strong>:message</strong></p>') !!}

Si vous voulez laisser un message à propos de votre commande, merci de bien vouloir le renseigner dans le champ
ci-contre

@include('components.form.textarea', [
    'name' => 'comment',
    'value' => old('comment') ?? '',
])

@push('js')
    <script>
        function handleDeliveries() {
            var $deliveryInputs = $('#delivery_mode input.delivery_mode');

            $deliveryInputs.change(function() {
                var $currentDelivery = $(this);
                var deliveryTypeId = $('input[name=delivery_type_id]:checked').val();

                if ($currentDelivery.hasClass('at_house')) {
                    $('#delivery_addresses').closest('.card').removeClass('d-none');
                } else {
                    $('#delivery_addresses').closest('.card').addClass('d-none');
                }

                var deliveryId = $currentDelivery.val();
                refreshBasketTotal(deliveryId, deliveryTypeId);
            });

            var $preselected = $deliveryInputs.filter(':checked').first();

            if ($preselected.length) {
                $preselected.trigger('change');
            } else {
                $('#delivery_addresses').closest('.card').addClass('d-none');
            }
        }

        handleDeliveries();
    </script>
@endpush
