@extends('layouts.admin')

@section('content')
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="card-body">
            <div class="d-md-flex align-items-center">
              <div>
                <h4 class="card-title">Detail Pemesanan</h4>
              </div>
            </div>
            <div class="table-responsive mt-4">
              <div class="row">
                   <div class="col-md-7">
                </div>
                <div class="col-md-5 d-flex justify-content-end">
                    <form action="{{ route('admin.order.order_detail', $order->id) }}" method="GET" style="display: flex">
                        <input type="text" style="height: 40px" placeholder="Cari Nama Produk" name="q_name" class="form-control" value="{{ $q_name }}" id="name">
                        <button type="submit" style="height: 40px; width: 50px !important; margin-left: 20px" class="btn btn-sm btn-secondary rounded-2">Cari</button>
                    </form>
                </div>
              </div>
              <table class="table mb-0 text-nowrap varient-table align-middle fs-3">
                <thead>
                  <tr>
                    <th scope="col" class="px-0 text-muted">Produk</th>
                    <th scope="col" class="px-0 text-muted">Jumlah</th>
                    <th scope="col" class="px-0 text-muted">Harga</th>
                    <th scope="col" class="px-0 text-muted">Diskon?</th>
                    <th scope="col" class="px-0 text-muted">Harga Potongan</th>
                    <th scope="col" class="px-0 text-muted">Total</th>
                  </tr>
                </thead>
                <tbody>
                    @if (!empty($q_name))
                        @if (count($order_detail) == 0)
                            <tr style="text-align: center">
                                <td colspan="2">Data Belum Ada</td>
                            </tr>
                        @endif
                    @endif
                    @foreach ($order_detail as $item)
                        <tr>
                            <td class="px-0">{{ $item->product->name }}</td>
                            <td class="px-0">{{ $item->amount }}</td>
                            <td class="px-0">Rp. {{ number_format($item->product->price) }}</td>
                            <td class="px-0">
                              @if ($item->is_discount)
                                Ya
                              @else
                                Tidak
                              @endif
                            </td>
                            <td class="px-0">Rp. {{ number_format($item->discount_price) }}%</td>
                            <td class="px-0">
                              @if ($item->is_discount) 
                                  Rp. {{ number_format(($item->product->price * (1 - ($item->product->discount_price / 100))) * $item->amount) }}
                              @else
                                  Rp. {{ number_format($item->product->price * $item->amount) }}
                              @endif
                            </td>
                        </tr>
                     
                    @endforeach
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
@endsection