<?php include __DIR__ . '/../header.php'; ?>

<div class="container-fluid">

    <div class="row mb-4">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <h1 class="h3 mb-1">
                        <i class="bi bi-arrow-return-left me-2 text-warning"></i>
                        <?= __('returns.page_title', 'مرتجعات الطلب') ?> #<?= (int)$order['id'] ?>
                    </h1>
                </div>
                <a href="/admin/orders/view/<?= (int)$order['id'] ?>" class="btn btn-outline-secondary">
                    <i class="bi bi-arrow-right me-1"></i>
                    <?= __('actions.back', 'رجوع') ?>
                </a>
            </div>
        </div>
    </div>

    <?php if (empty($returns)): ?>
    <div class="alert alert-light border text-center py-5">
        <i class="bi bi-inbox display-4 text-muted d-block mb-2"></i>
        <?= __('returns.no_returns', 'لا توجد مرتجعات لهذا الطلب') ?>
    </div>
    <?php else: ?>
    <div class="card border-0 shadow-sm">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>#</th>
                            <th><?= __('returns.col_type',     'النوع') ?></th>
                            <th><?= __('returns.col_qty',      'الكمية') ?></th>
                            <th><?= __('returns.col_reason',   'السبب') ?></th>
                            <th><?= __('returns.col_notes',    'ملاحظات') ?></th>
                            <th><?= __('returns.col_received', 'تاريخ الاستلام') ?></th>
                            <th><?= __('returns.col_stock',    'المخزون') ?></th>
                            <th><?= __('returns.col_date',     'التاريخ') ?></th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($returns as $ret): ?>
                        <?php
                        $typeLabels = [
                            'shipping_refused' => __('returns.type_shipping', 'رفض الزبون'),
                            'admin_request'    => __('returns.type_admin',    'مشكلة منتج'),
                            'partial'          => __('returns.type_partial',  'جزئي'),
                        ];
                        ?>
                        <tr>
                            <td><?= (int)$ret['id'] ?></td>
                            <td>
                                <span class="badge bg-secondary">
                                    <?= htmlspecialchars($typeLabels[$ret['type']] ?? $ret['type']) ?>
                                </span>
                            </td>
                            <td class="fw-bold"><?= (int)$ret['quantity'] ?></td>
                            <td><?= htmlspecialchars($ret['reason'] ?? '—') ?></td>
                            <td class="text-muted small"><?= htmlspecialchars($ret['admin_notes'] ?? '—') ?></td>
                            <td><?= $ret['received_at'] ? date('d/m/Y', strtotime($ret['received_at'])) : '—' ?></td>
                            <td>
                                <?php if ($ret['stock_restored']): ?>
                                    <span class="badge bg-success">
                                        <i class="bi bi-check"></i> <?= __('returns.stock_yes', 'أُعيد') ?>
                                    </span>
                                <?php else: ?>
                                    <span class="badge bg-danger">
                                        <i class="bi bi-x"></i> <?= __('returns.stock_no', 'لم يُعد') ?>
                                    </span>
                                <?php endif; ?>
                            </td>
                            <td class="text-muted small">
                                <?= date('d/m/Y H:i', strtotime($ret['created_at'])) ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <?php endif; ?>

</div>

<?php include __DIR__ . '/../footer.php'; ?>