@extends('layouts.app')

@section('content')

    <div class="px-3 row">
        <div class="col-xl-6">
            <form class="row" action="{{ route('maf_order.update', $maf_order) }}" method="post">
                <div class="">
                    <h4>Заказ МАФ</h4>
                    @csrf

                    <input type="hidden" id="product_id" name="product_id" value="{{ $maf_order->product_id }}">
                    @include('partials.input', ['name' => 'product_name', 'title' => 'МАФ', 'disabled' => true, 'value' => $maf_order->product->common_name])
                    @include('partials.input', ['name' => 'order_number', 'title' => 'Номер заказа', 'required' => false, 'value' => $maf_order->order_number, 'disabled' => $maf_order->products_sku->count()])
                    @include('partials.select', ['name' => 'status', 'title' => 'Статус', 'options' => ['заказан', 'на складе'], 'key_as_val' => true, 'value' => $maf_order->status, 'disabled' => $maf_order->products_sku->count()])
                    @include('partials.input', ['name' => 'quantity', 'title' => 'Количество', 'type' => 'number', 'required' => true, 'value' => $maf_order->quantity, 'required' => true, 'disabled' => $maf_order->products_sku->count()])

                    @include('partials.input', ['name' => 'in_stock', 'title' => 'Остаток', 'type' => 'number', 'required' => true, 'value' => $maf_order->in_stock, 'required' => true, 'disabled' => $maf_order->products_sku->count() ])

                    @if($maf_order->products_sku->count())
                        <div class="row">
                            <div class="buttons offset-md-4 col-md-8 ">
                                <a href="{{ url()->previous() }}" class="btn btn-primary">Назад</a>
                            </div>
                        </div>
                    @else
                        @include('partials.submit', ['name' => 'Сохранить', 'deleteDisabled' => $maf_order->products_sku->count(), 'delete' => ['form_id' => 'destroy', 'title' => 'Удалить']])
                        @if($maf_order->status == 'заказан')
                            <div class="row mt-3">
                                <div class="buttons offset-md-4 col-md-8 ">
                                    <a href="#" class="btn btn-primary" onclick="$('#set-status').submit();">На складе</a>
                                </div>
                            </div>
                        @endif


                    @endif
                </div>
            </form>
        </div>

        <div class="col-xl-6">
            <h3>Площадки, куда отгружен МАФ</h3>
            @foreach($maf_order->products_sku as $product_sku)
                <div>
                    <a href="{{ route('order.show', $product_sku->order) }}">
                        {{ $product_sku->order->common_name }}
                    </a>
                </div>
            @endforeach
        </div>

    </div>

    <div class="visually-hidden d-none">
        <form action="{{ route('maf_order.set_in_stock', $maf_order) }}" method="post" id="set-status">
            @csrf
        </form>
        <form action="{{ route('maf_order.delete', $maf_order) }}" id="destroy" method="post">
            @csrf
            @method('DELETE')
        </form>
    </div>
@endsection

