@extends('Shop.layout.layout', [
    'title' => __('Commande'),
])

@section('content')
    @php
        if ($errors->registration->all()) {
            $classIdent = 'd-none';
            $classRegister = '';
        } else {
            $classIdent = '';
            $classRegister = 'd-none';
        }
    @endphp
    <div class="row">
        <div class="@if ($basket['count']) col-sm-12 col-lg-8 @else col-12 @endif">
            @if (App\Repositories\Shop\Customers::isNotConnected())
                <p>
                    <a href="#" id="customer" class="pr-5">Déja client ?</a>
                    <button class="btn btn-secondary" id="register">Créez mon compte</button>
                </p>

                <x-layout.collapse id="identification" title="Déjà client"
                    class="{{ $classIdent }} identification rounded-lg" uncollapsed=true>
                    @include('Shop.auth.partials.login')
                </x-layout.collapse>

                <x-layout.collapse id="personal_data" title="Informations personnelles"
                    class="{{ $classRegister }} personal_data rounded-lg" uncollapsed=true>
                    @include('Shop.auth.partials.register')
                </x-layout.collapse>
            @else
                {{ Form::open(['route' => 'Shop.Orders.store', 'id' => 'order-form', 'autocomplete' => 'off']) }}
                @include('Shop.Orders.partials.registered')
                {!! Form::close() !!}
            @endif

        </div>
        @if ($basket['count'])
            <div class="col-sm-12 col-lg-4">
                <x-card class='shadow'>
                    <div id="basketTotal">
                        @include('Shop.Baskets.partials.basketTotal', [
                            'basket' => $basket,
                            'sale_channel' => $basket['sale_channel'] ?? null,
                        ])
                    </div>
                </x-card>
            </div>
        @endif
    </div>
@endsection

@include('load.layout.chevron')

@prepend('js')
    <script>
        $('#customer').click(function() {
            $(".personal_data").addClass('d-none');
            $('.identification').removeClass('d-none');
            $('#identification').collapse('show');
        });

        $('#register').click(function() {
            $('.identification').addClass('d-none');
            $(".personal_data").removeClass('d-none');
            $('#personal_data').collapse('show');
        });

        function refreshBasketTotal(deliveryId, deliveryTypeId) {
            var safeDeliveryId = deliveryId !== undefined && deliveryId !== null ? deliveryId : '';
            var safeDeliveryTypeId = deliveryTypeId !== undefined && deliveryTypeId !== null ? deliveryTypeId : '';
            var options = safeDeliveryId + '/' + safeDeliveryTypeId;
            $.get("{{ Route('Shop.Basket.getBasketTotal') }}/" + options, function(data) {
                $('#basketTotal').html(data);
            });
        }

        initChevron();
    </script>
@endprepend
