<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?><?= e($warehouse->name_ar) ?><?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/inventory/warehouses/<?= (int) $warehouse->id ?>/edit" class="btn btn-outline"><i data-lucide="edit-3" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> تعديل</a>
<a href="/inventory/warehouses" class="btn btn-outline"><i data-lucide="arrow-right" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> العودة للقائمة</a>
<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>

<?php
$isActive = (int) $warehouse->is_active;
$typeLabel = $warehouseTypes[$warehouse->warehouse_type] ?? $warehouse->warehouse_type;
?>

<!-- Warehouse Info Card -->
<div class="card" style="margin-bottom:20px;">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
        <i data-lucide="warehouse" style="width:18px;height:18px;color:#0D7377;"></i>
        <h3 style="margin:0;color:#0D7377;font-size:15px;">بيانات المخزن</h3>
    </div>
    <div style="padding:20px;">
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:0;">
            <table style="width:100%;font-size:14px;">
                <tr>
                    <td style="padding:10px 0;color:#6B7280;width:40%;">الكود</td>
                    <td style="padding:10px 0;font-weight:600;">
                        <code style="font-size:12px;background:#F3F4F6;padding:2px 8px;border-radius:4px;"><?= e($warehouse->code) ?></code>
                    </td>
                </tr>
                <tr>
                    <td style="padding:10px 0;color:#6B7280;">الاسم بالعربي</td>
                    <td style="padding:10px 0;font-weight:600;"><?= e($warehouse->name_ar) ?></td>
                </tr>
                <tr>
                    <td style="padding:10px 0;color:#6B7280;">الاسم بالإنجليزي</td>
                    <td style="padding:10px 0;"><?= e($warehouse->name_en ?? '—') ?></td>
                </tr>
                <tr>
                    <td style="padding:10px 0;color:#6B7280;">النوع</td>
                    <td style="padding:10px 0;">
                        <span style="display:inline-block;padding:2px 10px;border-radius:10px;font-size:12px;font-weight:600;background:#F0FDFA;color:#0D7377;">
                            <?= e($typeLabel) ?>
                        </span>
                    </td>
                </tr>
                <tr>
                    <td style="padding:10px 0;color:#6B7280;">الموقع</td>
                    <td style="padding:10px 0;"><?= e($warehouse->location_ar ?? '—') ?></td>
                </tr>
            </table>
            <table style="width:100%;font-size:14px;">
                <tr>
                    <td style="padding:10px 0;color:#6B7280;width:40%;">أمين المخزن</td>
                    <td style="padding:10px 0;font-weight:600;"><?= $keeper ? e($keeper['full_name_ar']) : '—' ?></td>
                </tr>
                <tr>
                    <td style="padding:10px 0;color:#6B7280;">السعة</td>
                    <td style="padding:10px 0;"><?= $warehouse->capacity_units ? (int) $warehouse->capacity_units . ' وحدة' : '—' ?></td>
                </tr>
                <tr>
                    <td style="padding:10px 0;color:#6B7280;">الهاتف</td>
                    <td style="padding:10px 0;direction:ltr;text-align:right;"><?= e($warehouse->phone ?? '—') ?></td>
                </tr>
                <tr>
                    <td style="padding:10px 0;color:#6B7280;">الحالة</td>
                    <td style="padding:10px 0;">
                        <?php if ($isActive): ?>
                            <span style="color:#059669;font-weight:600;">● نشط</span>
                        <?php else: ?>
                            <span style="color:#DC2626;font-weight:600;">● معطل</span>
                        <?php endif; ?>
                    </td>
                </tr>
                <tr>
                    <td style="padding:10px 0;color:#6B7280;">ملاحظات</td>
                    <td style="padding:10px 0;"><?= e($warehouse->notes ?? '—') ?></td>
                </tr>
            </table>
        </div>
    </div>
</div>

<!-- Stock Summary -->
<div class="card" style="margin-bottom:20px;">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
        <i data-lucide="package" style="width:18px;height:18px;color:#D97706;"></i>
        <h3 style="margin:0;color:#D97706;font-size:15px;">ملخص المخزون</h3>
    </div>
    <?php if (!empty($stockSummary)): ?>
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th>الصنف</th>
                    <th>SKU</th>
                    <th>وحدة القياس</th>
                    <th>الكمية</th>
                    <th>الحد الأدنى</th>
                    <th>الحد الأقصى</th>
                    <th>الحالة</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($stockSummary as $item): ?>
                <?php $isLow = $item['min_level'] !== null && (float) $item['quantity'] <= (float) $item['min_level']; ?>
                <tr>
                    <td style="font-weight:600;"><?= e($item['name_ar']) ?></td>
                    <td><code style="font-size:11px;background:#F3F4F6;padding:2px 6px;border-radius:4px;"><?= e($item['sku'] ?? '—') ?></code></td>
                    <td><?= e($item['unit_of_measure'] ?? '—') ?></td>
                    <td style="font-weight:700;color:<?= $isLow ? '#DC2626' : '#059669' ?>;"><?= (int) $item['quantity'] ?></td>
                    <td><?= $item['min_level'] !== null ? (int) $item['min_level'] : '—' ?></td>
                    <td><?= $item['max_level'] !== null ? (int) $item['max_level'] : '—' ?></td>
                    <td>
                        <?php if ($isLow): ?>
                            <span style="display:inline-flex;align-items:center;gap:4px;padding:2px 10px;border-radius:10px;font-size:12px;font-weight:600;background:#FEE2E2;color:#DC2626;">
                                <i data-lucide="alert-triangle" style="width:13px;height:13px;"></i> منخفض
                            </span>
                        <?php else: ?>
                            <span style="display:inline-flex;align-items:center;gap:4px;padding:2px 10px;border-radius:10px;font-size:12px;font-weight:600;background:#ECFDF5;color:#059669;">
                                <i data-lucide="check-circle" style="width:13px;height:13px;"></i> طبيعي
                            </span>
                        <?php endif; ?>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php else: ?>
    <div style="padding:40px;text-align:center;color:#9CA3AF;font-size:14px;">
        <i data-lucide="package-open" style="width:36px;height:36px;color:#D1D5DB;margin-bottom:10px;"></i>
        <div>لا توجد أصناف في هذا المخزن حالياً</div>
    </div>
    <?php endif; ?>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
    if (typeof lucide !== 'undefined') {
        lucide.createIcons();
    }
});
</script>
<?php $__template->endSection(); ?>
