@extends('layouts.web')

@section('content')
<section class="py-5">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="order-md-last">
                    <h4 class="d-flex justify-content-between align-items-center mb-3">
                        <span class="text-primary">Histori Pesanan Kamu</span>
                        <span class="badge bg-primary rounded-pill">{{ count($order) }}</span>
                    </h4>
                    <ul class="list-group mb-3">
                        @if (count($order) == 0)
                            <div class="align-self-center">
                                Data pesanan mu kosong
                            </div>
                        @endif
                        @foreach ($order as $item)
                            <li class="list-group-item d-flex justify-content-between lh-sm">
                                <div class="d-flex justify-content-between">
                                    <div class="d-flex justify-content-center" style="flex-direction: column; padding-left: 20px">
                                        <small class="text-body-secondary">Id Pesanan #{{ $item->id }}</small>

                                        <h6 class="my-0">Produk yang dibeli : </h6>
                                        @php
                                            $total = 0;   
                                        @endphp

                                        @foreach ($item->getProductFromOrder($item->id) as $item)
                                            <small class="text-body-secondary">{{ $item->product->name }} ({{ $item->amount }} kg)</small>
                                            <small class="text-body-secondary">
                                                @if ($item->product->is_discount) 
                                                    @php
                                                        $total += ($item->product->price * (1 - ($item->product->discount_price / 100)));
                                                    @endphp
                                                    <div class="price" style="text-decoration: line-through; font-size: 15px">Rp. {{ number_format($item->product->price) }} </div>
                                                    <div class="price" style="font-size: 15px">Rp. {{ number_format(($item->product->price * (1 - ($item->product->discount_price / 100)))) }}</div>
                                                @else
                                                    @php
                                                        $total += $item->product->price;
                                                    @endphp
                                                    <div class="price" style="font-size: 15px">Rp. {{ number_format($item->product->price) }} </div>
                                                @endif
                                            </small>
                                        @endforeach

                                        <h6 class="my-0" style="padding-top: 10px">Total : Rp. {{ number_format($total) }}</h6>
                                    </div>
                                </div>
                                <div class="d-flex justify-content-between align-items-center">
                                    @if ($item->status == 0)
                                        Sedang di Proses
                                    @elseif($item->status == 1)
                                        Sedang dalam Perjalanan
                                    @else
                                        Barang Sudah di Terima
                                    @endif
                                </div>
                            </li>  
                        @endforeach
                    </ul>
                
                </div>
            </div>
        </div>
    </div>
</section>
@endsection