@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">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') }}" method="GET" style="display: flex">
                        <input type="text" style="height: 40px" placeholder="Cari Nama" 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">Nama Pemesan</th>
                    <th scope="col" class="px-0 text-muted">Whatsapp</th>
                    <th scope="col" class="px-0 text-muted">Email Pemesan</th>
                    <th scope="col" class="px-0 text-muted">Total Belanja</th>
                    <th scope="col" class="px-0 text-muted">Status</th>
                    <th scope="col" class="px-0 text-muted" class="px-0 text-muted">
                      Aksi
                    </th>
                  </tr>
                </thead>
                <tbody>
                    @if (!empty($q_name) || !empty($q_order_date))
                        @if (count($order) == 0)
                            <tr style="text-align: center">
                                <td colspan="5">Data Belum Ada</td>
                            </tr>
                        @endif
                    @endif
                    @foreach ($order as $item)
                        <tr>
                          <td class="px-0">{{ $item->getCustomerName($item->id) }}</td>
                          <td class="px-0"><a href="https://wa.me/{{$item->getCustomerPhoneNumber($item->id)}}/?text=Halo Kak, Kami dari Pasar Nelayan untuk barang kakak sedang {status_order}"><i class="fa-brands fa-whatsapp"></i> {{ $item->getCustomerPhoneNumber($item->id) }}</a> </td>
                          <td class="px-0">{{ $item->getCustomerEmail($item->id) }}</td>
                          <td class="px-0">Rp. {{ number_format($item->getTotalShopping($item->id)) }}</td>
                          <td class="px-0">
                            @if ($item->status == 0)
                                Sedang di Proses
                            @elseif($item->status == 1)
                                Sedang dalam Perjalanan
                            @else
                                Barang Sudah di Terima
                            @endif
                          </td>
                          <td>
                              <a href="{{ route('admin.order.edit', $item->id) }}" style="text-decoration: none"> 
                                  <button class="btn btn-warning btn-sm text-white mb-0 me-0" type="button"><i class="mdi mdi-pencil"></i>Edit</button>
                              </a>
                              <a href="{{ route('admin.order.order_detail', $item->id) }}" style="text-decoration: none"> 
                                  <button class="btn btn-secondary btn-sm text-white mb-0 me-0" type="button"><i class="mdi mdi-pencil"></i>Detail Pemesanan</button>
                              </a>
                              <form action="{{ route('admin.order.delete') }}" style="display: inline-block" method="POST">
                                  @csrf @method('DELETE')
                                  <input type="hidden" value="{{ $item->id }}" name="id">
                                  <button class="btn btn-danger btn-sm text-white mb-0 me-0" type="submit"><i class="mdi mdi-delete"></i>Hapus</button>
                              </form>
                          </td>
                        </tr>
                    @endforeach
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
@endsection