<?php
$page_title = 'Warehouse Automation';
require_once __DIR__ . '/../config.php';
if (session_status() === PHP_SESSION_NONE) { session_start(); }
if (!isset($_SESSION['admin_id'])) { redirect(SITE_URL . '/admin/login.php'); }
require_once __DIR__ . '/header.php';
?>

<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:24px;">
    <div>
        <h2 style="font-family:'Outfit', sans-serif; font-size:1.8rem; color:#0f172a; margin:0;">Warehouse Automation Hub</h2>
        <p style="color:#64748b; font-size:0.95rem; margin-top:5px;">Bin management, pick path optimization, and dispatch scheduling.</p>
    </div>
    <div style="display:flex; gap:10px;">
        <button style="background:#f1f5f9; color:#334155; border:1px solid #cbd5e1; padding:8px 16px; border-radius:8px; font-size:0.85rem; cursor:pointer;"><i class="fas fa-qrcode" style="margin-right:6px;"></i> Scan QR/RFID</button>
        <button style="background:#2563eb; color:#fff; border:none; padding:8px 16px; border-radius:8px; font-size:0.85rem; font-weight:600; cursor:pointer;"><i class="fas fa-plus" style="margin-right:6px;"></i> New Dispatch</button>
    </div>
</div>

<!-- Warehouse Stats -->
<div class="grid-4" style="margin-bottom:24px;">
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0; display:flex; align-items:center; gap:15px;">
        <div style="width:45px; height:45px; border-radius:10px; background:#dbeafe; color:#2563eb; display:flex; align-items:center; justify-content:center; font-size:1.3rem;"><i class="fas fa-boxes"></i></div>
        <div>
            <div style="color:#64748b; font-size:0.8rem; font-weight:600;">TOTAL BINS</div>
            <div style="color:#0f172a; font-size:1.4rem; font-weight:700;">2,480</div>
        </div>
    </div>
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0; display:flex; align-items:center; gap:15px;">
        <div style="width:45px; height:45px; border-radius:10px; background:#dcfce7; color:#10b981; display:flex; align-items:center; justify-content:center; font-size:1.3rem;"><i class="fas fa-check-circle"></i></div>
        <div>
            <div style="color:#64748b; font-size:0.8rem; font-weight:600;">OCCUPANCY</div>
            <div style="color:#0f172a; font-size:1.4rem; font-weight:700;">78%</div>
        </div>
    </div>
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0; display:flex; align-items:center; gap:15px;">
        <div style="width:45px; height:45px; border-radius:10px; background:#fef3c7; color:#d97706; display:flex; align-items:center; justify-content:center; font-size:1.3rem;"><i class="fas fa-robot"></i></div>
        <div>
            <div style="color:#64748b; font-size:0.8rem; font-weight:600;">AGV ROBOTS</div>
            <div style="color:#0f172a; font-size:1.4rem; font-weight:700;">12 Active</div>
        </div>
    </div>
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0; display:flex; align-items:center; gap:15px;">
        <div style="width:45px; height:45px; border-radius:10px; background:#ede9fe; color:#7c3aed; display:flex; align-items:center; justify-content:center; font-size:1.3rem;"><i class="fas fa-truck-loading"></i></div>
        <div>
            <div style="color:#64748b; font-size:0.8rem; font-weight:600;">TODAY'S DISPATCHES</div>
            <div style="color:#0f172a; font-size:1.4rem; font-weight:700;">34</div>
        </div>
    </div>
</div>

<div class="grid-2">
    <!-- Warehouse Grid View -->
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0;">
        <h3 style="margin:0 0 20px; font-size:1.15rem; color:#0f172a;"><i class="fas fa-th" style="color:#3b82f6; margin-right:8px;"></i> Smart Bin Grid (Zone A)</h3>
        <div style="display:grid; grid-template-columns:repeat(8, 1fr); gap:6px; margin-bottom:15px;">
            <?php for ($i = 1; $i <= 32; $i++): ?>
            <div style="height:35px; border-radius:4px; display:flex; align-items:center; justify-content:center; font-size:0.6rem; font-weight:bold; color:#fff;
                background:<?= $i % 7 === 0 ? '#ef4444' : ($i % 5 === 0 ? '#f59e0b' : '#10b981') ?>;">
                <?= $i % 7 === 0 ? '!' : ($i % 5 === 0 ? '▲' : '✓') ?>
            </div>
            <?php endfor; ?>
        </div>
        <div style="display:flex; gap:20px; font-size:0.8rem; color:#64748b;">
            <span><span style="display:inline-block; width:12px; height:12px; background:#10b981; border-radius:3px; margin-right:5px;"></span> Occupied</span>
            <span><span style="display:inline-block; width:12px; height:12px; background:#f59e0b; border-radius:3px; margin-right:5px;"></span> Low Stock</span>
            <span><span style="display:inline-block; width:12px; height:12px; background:#ef4444; border-radius:3px; margin-right:5px;"></span> Needs Restock</span>
        </div>
    </div>

    <!-- Dispatch Dock Scheduler -->
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0;">
        <h3 style="margin:0 0 20px; font-size:1.15rem; color:#0f172a;"><i class="fas fa-calendar-alt" style="color:#8b5cf6; margin-right:8px;"></i> Dispatch Dock Scheduler</h3>
        
        <div style="border:1px solid #e2e8f0; border-radius:8px; padding:15px; margin-bottom:12px; display:flex; justify-content:space-between; align-items:center;">
            <div>
                <h4 style="margin:0 0 5px; font-size:0.95rem; color:#0f172a;">Dock #1 — Truck MH14-AB-8821</h4>
                <p style="margin:0; font-size:0.8rem; color:#64748b;">Loading: SS 304 Sheets (18 pallets) • ETA: 11:30 AM</p>
            </div>
            <span style="background:#dcfce7; color:#166534; padding:4px 10px; border-radius:12px; font-size:0.75rem; font-weight:bold;">Loading</span>
        </div>
        
        <div style="border:1px solid #e2e8f0; border-radius:8px; padding:15px; margin-bottom:12px; display:flex; justify-content:space-between; align-items:center;">
            <div>
                <h4 style="margin:0 0 5px; font-size:0.95rem; color:#0f172a;">Dock #2 — Truck GJ05-XY-4419</h4>
                <p style="margin:0; font-size:0.8rem; color:#64748b;">Unloading: Raw coils from JSW (12 MT) • Arrived: 10:45 AM</p>
            </div>
            <span style="background:#dbeafe; color:#1d4ed8; padding:4px 10px; border-radius:12px; font-size:0.75rem; font-weight:bold;">Unloading</span>
        </div>
        
        <div style="border:1px solid #e2e8f0; border-radius:8px; padding:15px; display:flex; justify-content:space-between; align-items:center;">
            <div>
                <h4 style="margin:0 0 5px; font-size:0.95rem; color:#0f172a;">Dock #3 — Available</h4>
                <p style="margin:0; font-size:0.8rem; color:#64748b;">Next scheduled: 2:00 PM (Container pickup)</p>
            </div>
            <span style="background:#f1f5f9; color:#64748b; padding:4px 10px; border-radius:12px; font-size:0.75rem; font-weight:bold;">Free</span>
        </div>
    </div>
</div>

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