@foreach($parentStoreOrdersAsClient as $parentOrder)
<?php
    $associatedOrders = $parentOrder->allAssociatedOrders();
?>
<div class="card">
    <div class="card-header">
        <div class="d-flex justify-content-between align-items-start">
            <div>
                <b>{{ $parentOrder->iid }}</b>
            </div>
            <div class="d-flex align-items-center">
                <a href="{{ route('admin.orders.view.preview-invoice', $parentOrder) }}" class="text-primary" target="_blank">Invoice</a>
            </div>
        </div>
    </div>
    <div class="card-body">
        <div class="">
            <table class="table table-sm table-bordered table-hover">
            <thead class="bg-warning bg-opacity-10">
                <tr>
                    <th>IID</th>
                    <th>Created At</th>
                    <th>Amount</th>
                    <th>Trx</th>
                </tr>
            </thead>
            <tbody>
                @foreach ($associatedOrders as $order)
                    <tr @if ($order->is_cancelled) class="cancelled-order" @endif>
                        <td><a href="{{ route('admin.orders.view.dashboard', $order) }}">{{ $order->orderNumber() }}</a>
                        </td>
                        <td>{{ friendly_date($order->created_at) }}</td>
                        <td>{{ displayAmount('$', $order->order_total) }}</td>
                        <td>
                            <div>
                                @include('app.my-account.admin.orders.forms.create-charge')
                            </div>
                            <div>
                                <table class="table table-sm table-hover table-striped table-bordered mb-0">
                                    <thead class="bg-warning bg-opacity-10">
                                        <tr>
                                            <th>Date</th>
                                            <th>Charge/Refund</th>
                                            <th>Amount</th>
                                            <th>Payment Method</th>
                                            <th></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach ($order->financialTransactions as $transaction)
                                            <tr>
                                                <td>{{ friendly_date($transaction->created_at) }}</td>
                                                <td>{{ $transaction->charge_or_refund }}</td>
                                                <td>${{ $transaction->amount }}</td>
                                                <td>{!! $transaction->paymentMethod->displayName() !!}</td>
                                                <td>
                                                    @if ($transaction->charge_or_refund == 'CHARGE')
                                                        @include('app.my-account.admin.orders.forms.create-refund')
                                                    @endif
                                                </td>
                                            </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                            </div>
                        </td>
                    </tr>
                @endforeach
            </tbody>
        </table>
        </div>
    </div>
</div>
@endforeach
