<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>المخازن<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/inventory/warehouses/create" class="btn btn-primary"><i data-lucide="plus" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> مخزن جديد</a>
<?php $__template->endSection(); ?>

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

<!-- Search / Filters -->
<div class="card" style="margin-bottom:20px;padding:15px;">
    <form method="GET" action="/inventory/warehouses" style="display:flex;gap:10px;align-items:end;flex-wrap:wrap;">
        <div style="flex:1;min-width:200px;">
            <label class="form-label" style="font-size:12px;">بحث</label>
            <input type="text" name="q" value="<?= e($filters['q'] ?? '') ?>" placeholder="ابحث بالاسم أو الكود..." class="form-input">
        </div>
        <div style="min-width:160px;">
            <label class="form-label" style="font-size:12px;">نوع المخزن</label>
            <select name="warehouse_type" class="form-select">
                <option value="">الكل</option>
                <?php foreach ($warehouseTypes as $typeKey => $typeLabel): ?>
                <option value="<?= e($typeKey) ?>" <?= ($filters['warehouse_type'] ?? '') === $typeKey ? 'selected' : '' ?>><?= e($typeLabel) ?></option>
                <?php endforeach; ?>
            </select>
        </div>
        <div style="min-width:120px;">
            <label class="form-label" style="font-size:12px;">الحالة</label>
            <select name="is_active" class="form-select">
                <option value="">الكل</option>
                <option value="1" <?= ($filters['is_active'] ?? '') === '1' ? 'selected' : '' ?>>نشط</option>
                <option value="0" <?= ($filters['is_active'] ?? '') === '0' ? 'selected' : '' ?>>معطل</option>
            </select>
        </div>
        <button type="submit" class="btn btn-outline"><i data-lucide="search" style="width:16px;height:16px;vertical-align:middle;"></i> بحث</button>
    </form>
</div>

<!-- Warehouses Table -->
<?php if (!empty($warehouses)): ?>
<div class="card">
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th>الكود</th>
                    <th>الاسم</th>
                    <th>النوع</th>
                    <th>الموقع</th>
                    <th>أمين المخزن</th>
                    <th>الحالة</th>
                    <th>إجراءات</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($warehouses as $w): ?>
                <tr>
                    <td><code style="font-size:12px;background:#F3F4F6;padding:2px 8px;border-radius:4px;"><?= e($w['code']) ?></code></td>
                    <td style="font-weight:600;"><?= e($w['name_ar']) ?></td>
                    <td>
                        <span style="display:inline-block;padding:2px 10px;border-radius:10px;font-size:12px;font-weight:600;background:#F0FDFA;color:#0D7377;">
                            <?= e($warehouseTypes[$w['warehouse_type']] ?? $w['warehouse_type']) ?>
                        </span>
                    </td>
                    <td><?= e($w['location_ar'] ?? '—') ?></td>
                    <td><?= e($w['keeper_name'] ?? '—') ?></td>
                    <td>
                        <?php if ($w['is_active']): ?>
                            <span style="color:#059669;font-weight:600;">● نشط</span>
                        <?php else: ?>
                            <span style="color:#DC2626;font-weight:600;">● معطل</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <div style="display:flex;gap:5px;">
                            <a href="/inventory/warehouses/<?= (int) $w['id'] ?>" class="btn btn-sm btn-outline" style="font-size:12px;">
                                <i data-lucide="eye" style="width:13px;height:13px;vertical-align:middle;margin-left:3px;"></i> عرض
                            </a>
                            <a href="/inventory/warehouses/<?= (int) $w['id'] ?>/edit" class="btn btn-sm btn-outline" style="font-size:12px;">
                                <i data-lucide="edit-3" style="width:13px;height:13px;vertical-align:middle;margin-left:3px;"></i> تعديل
                            </a>
                        </div>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>

<?php if (isset($pagination) && ($pagination['last_page'] ?? 1) > 1): ?>
<div style="padding:15px;">
    <?php $__template->include('Shared.Components.pagination', ['pagination' => $pagination]); ?>
</div>
<?php endif; ?>

<?php else: ?>
<div class="card" style="padding:60px 20px;text-align:center;">
    <div style="margin-bottom:15px;">
        <i data-lucide="warehouse" style="width:48px;height:48px;color:#D1D5DB;"></i>
    </div>
    <h3 style="color:#6B7280;margin:0 0 8px;">لا توجد مخازن</h3>
    <p style="color:#9CA3AF;font-size:14px;margin:0 0 20px;">
        <?php if (!empty($filters['q']) || !empty($filters['warehouse_type']) || ($filters['is_active'] ?? '') !== ''): ?>
            لا توجد نتائج مطابقة لبحثك. جرب تغيير معايير البحث.
        <?php else: ?>
            ابدأ بإضافة مخزن جديد.
        <?php endif; ?>
    </p>
    <a href="/inventory/warehouses/create" class="btn btn-primary"><i data-lucide="plus" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> مخزن جديد</a>
</div>
<?php endif; ?>

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