@extends('layout.index', [
    'title' => __('shop.orders.title'),
    'subtitle' => __('shop.orders.edit'),
    'breadcrumb' => ['Commandes']
])

@section('content')
    {{ Form::open(['route' => 'Admin.Shop.Orders.store', 'id' => 'order-form', 'autocomplete' => 'off']) }}
        <input type="hidden" name="id" value="{{ $order['id'] ?? null }}">
        <x-card>
            <div class="row">
                <div class="col-6">
                    <h4>{{ $order['delivery']['name'] }} </h4>
                </div>
                <div class="col-6 text-right">
                    <x-save />
                </div>
            </div>

            <div class="row mb-3">
                <div class="col-6">
                    <h3>
                        {{ $order['customer']['last_name'] }} {{ $order['customer']['first_name'] }}
                    </h3>
                    <div class="row">
                        <div class="col-6">
                            <x-card title="Adresse de facturation" classBody="mt-3">
                                @if ($order['invoice']['address'])
                                    {{ $order['invoice']['address']['address'] }}<br/>
                                    @isset ($order['invoice']['address']['address2'])
                                        {{ $order['invoice']['address']['address2'] }}<br/>
                                    @endisset
                                    {{ $order['invoice']['address']['zipcode'] }}
                                    {{ $order['invoice']['address']['city'] }}<br/>
                                @endif
                            </x-card>
                        </div>
                        <div class="col-6">
                            <x-card title="Adresse de livraison" classBody="mt-3">
                                @if ($order['delivery_address'])
                                    {{ $order['delivery_address']['address'] }}<br/>
                                    @isset ($order['delivery_address']['address2'])
                                        {{ $order['delivery_address']['address2'] }}<br/>
                                    @endisset
                                    {{ $order['delivery_address']['zipcode'] }}
                                    {{ $order['delivery_address']['city'] }}<br/>
                                @endif
                            </x-card>
                        </div>
                    </div>
                </div>
                <div class="col-6">
                    <div class="row mb-3">
                        <div class="col-6" style="font-size: 1.2em; font-weight: 500;">
                            Commande <br/>
                            du {{ Carbon\Carbon::parse($order['created_at'])->isoFormat('LLLL') }}
                        </div>
                        <div class="col-6">
                            @include('components.form.select', [
                                'label' => 'Statut',
                                'name' => 'status',
                                'list' => $statuses ?? [],
                                'value' => $order['status'],
                                'class' => 'select2',
                            ])
                        </div>
                    </div>
                    <div class="row mb-3">
                        <div class="col-6">
                            @include('components.form.select', [
                                'label' => 'Canal de vente',
                                'name' => 'sale_channel_id',
                                'list' => $sale_channels ?? [],
                                'value' => $order['sale_channel_id'],
                                'class' => 'select2',
                            ])
                        </div>
                        <div class="col-6">
                            @include('components.form.select', [
                                'label' => 'Règlement',
                                'name' => 'payment_type',
                                'list' => $payment_types ?? [],
                                'value' => $order['payment_type'],
                                'class' => 'select2',
                            ])
                        </div>
                    </div>
                    <div class="row mb-3">
                        <div class="col-4">
                            @include('components.form.select', [
                                'label' => 'Type de livraison',
                                'name' => 'delivery_type_id',
                                'list' => $delivery_types ?? [],
                                'value' => $order['delivery_type_id'],
                                'with_empty' => '',
                            ])
                        </div>
                        <div class="col-4">
                            @include('components.form.input', [
                                'label' => 'Référence colis',
                                'name' => 'delivery_ref',
                                'value' => $order['delivery_ref']  ?? null,
                            ])
                        </div>
                        <div class="col-4">
                            @include('components.form.input', [
                                'label' => 'Lien suivi',
                                'name' => 'delivery_link',
                                'value' => $order['delivery_link'] ?? null,
                            ])
                        </div>

                    </div>
                </div>
            </div>
            <div class="row mb-3">
                <div class="col-12">
                    @include('Admin.Shop.Orders.partials.detail', ['detail_type' => 'commande'])
                </div>
            </div>
        </x-card>
    {{ Form::close() }}
@endsection

@include('load.form.save')
@include('load.form.select2')

@push('js')
    <script>
        initSaveForm('#order-form');
        initSelect2();
    </script>
@endpush
