@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-9">
                <h5>
                    <a href="{{ route('Admin.Shop.Invoices.edit', ['id' => $order['invoice']['id']]) }}"
                        class="btn btn-success">
                        <i class="fa fa-fw fa-file-invoice"></i>
                    </a>
                    Commande : {{ $order['ref'] }}
                    <span class="small">
                        du {{ Carbon\Carbon::parse($order['created_at'])->isoFormat('LLLL') }}
                    </span>
                </h5>
            </div>
            <div class="col-3 text-right">
                <x-save />
            </div>
        </div>

        <div class="row mb-3">
            <div class="col-6">
                <h5>
                    @if ($order['customer']['company'])
                        Société : {{ $order['customer']['company'] }}<br />
                    @endif
                    {{ $order['customer']['first_name'] }} {{ $order['customer']['last_name'] }}
                </h5>

                <h6>
                    {{ $order['delivery']['name'] }}<br>
                    Canal de vente : {{ $order['sale_channel']['name'] ?? '' }}
                </h6>

                @if ($order['delivery_address'])
                    <x-card title="Adresse de livraison" classBody="mt-3">
                        @include('components.address-view', [
                            'address' => $order['delivery_address'],
                        ])
                    </x-card>
                @endif

                @if ($order['comment'])
                    <x-card title="Commentaire" class="mt-3">
                        {{ $order['comment'] }}
                    </x-card>
                @endif


            </div>
            <div class="col-6">
                <div class="row mb-3">
                    <div class="col-6">
                        @include('components.form.select', [
                            'label' => 'Statut',
                            'name' => 'status',
                            'list' => $statuses ?? [],
                            'value' => $order['status'],
                            '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>

                @if ($order['delivery']['at_house'])
                    <x-card title="Livraison">
                        <div class="row mb-3">
                            <div class="col-6">
                                @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-6">
                                @include('components.form.input', [
                                    'label' => 'Référence colis',
                                    'name' => 'delivery_ref',
                                    'value' => $order['delivery_ref'] ?? null,
                                ])
                            </div>
                        </div>
                        <div class="row mb-3">
                            <div class="col-12">
                                @include('components.form.input', [
                                    'label' => 'Lien suivi',
                                    'name' => 'delivery_link',
                                    'value' => $order['delivery_link'] ?? null,
                                ])
                            </div>
                        </div>
                    </x-card>
                @endif

            </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
