<?php $__env->startSection('content'); ?>
<div class="grid gap-4 md:grid-cols-2 xl:grid-cols-4">
    <?php $__currentLoopData = [
        ['label' => 'Users', 'value' => $stats['users']],
        ['label' => 'Connected Brokers', 'value' => $stats['connected_brokers']],
        ['label' => 'Active Bots', 'value' => $stats['active_bots']],
        ['label' => 'Instruments', 'value' => $stats['instruments']],
    ]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <div class="trade-card">
            <div class="text-sm text-slate-400"><?php echo e($stat['label']); ?></div>
            <div class="text-3xl font-bold text-white"><?php echo e($stat['value']); ?></div>
        </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</div>

<div class="trade-card mt-6">
    <div class="mb-4 flex flex-wrap items-center justify-between gap-3">
        <h3 class="text-lg font-semibold text-white">Market Feed (Admin Credentials)</h3>
        <a href="<?php echo e(route('broker')); ?>" class="trade-btn-ghost">Manage Admin FlatTrade Creds</a>
    </div>
    <?php if($marketFeed): ?>
        <p class="text-sm text-emerald-400">Connected — <?php echo e($marketFeed->client_id); ?> powers WebSocket + scan data for all users.</p>
        <p class="mt-1 text-xs text-slate-500">Last sync: <?php echo e($marketFeed->last_synced_at?->diffForHumans() ?? 'Never'); ?></p>
    <?php else: ?>
        <p class="text-sm text-rose-400">Not connected. Admin must save API credentials and complete OAuth on the FlatTrade Account page.</p>
    <?php endif; ?>
</div>

<div class="trade-card mt-6">
    <div class="mb-4 flex flex-wrap items-center justify-between gap-3">
        <h3 class="text-lg font-semibold text-white">Data Sync</h3>
        <div class="flex gap-2">
            <form method="POST" action="<?php echo e(route('admin.sync')); ?>"><?php echo csrf_field(); ?><button type="submit" class="trade-btn-primary">Trigger Sync</button></form>
            <a href="<?php echo e(route('admin.rulebook.edit')); ?>" class="trade-btn-ghost">Edit Rulebook</a>
            <a href="<?php echo e(route('admin.logs')); ?>" class="trade-btn-ghost">System Logs</a>
        </div>
    </div>
    <p class="text-sm text-slate-400">Last market tick: <?php echo e($stats['last_tick'] ? \Carbon\Carbon::parse($stats['last_tick'])->diffForHumans() : 'Never'); ?></p>
</div>

<div class="trade-card mt-6">
    <h3 class="mb-4 text-lg font-semibold text-white">Worker Health</h3>
    <div class="grid gap-3 md:grid-cols-3">
        <?php $__empty_1 = true; $__currentLoopData = $workers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $worker): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <div class="rounded-xl border border-trade-border bg-trade-panel p-4">
                <div class="font-semibold text-white"><?php echo e($worker->worker); ?></div>
                <div class="text-sm <?php echo e($worker->status === 'running' ? 'text-emerald-400' : 'text-slate-400'); ?>"><?php echo e(strtoupper($worker->status)); ?></div>
                <div class="mt-1 text-xs text-slate-500"><?php echo e($worker->last_heartbeat_at?->diffForHumans() ?? 'Never'); ?></div>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <p class="text-slate-500">No workers reported yet. Run artisan commands on VPS.</p>
        <?php endif; ?>
    </div>
</div>

<div class="trade-card mt-6 overflow-x-auto">
    <h3 class="mb-4 text-lg font-semibold text-white">Users</h3>
    <table class="w-full text-left text-sm">
        <thead class="border-b border-trade-border text-slate-400">
            <tr>
                <th class="pb-3 pr-4">Name</th>
                <th class="pb-3 pr-4">Email</th>
                <th class="pb-3 pr-4">Role</th>
                <th class="pb-3 pr-4">Broker</th>
                <th class="pb-3">Bot</th>
            </tr>
        </thead>
        <tbody>
            <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr class="border-b border-trade-border/50">
                    <td class="py-3 pr-4 text-white"><?php echo e($user->name); ?></td>
                    <td class="py-3 pr-4"><?php echo e($user->email); ?></td>
                    <td class="py-3 pr-4"><span class="rounded bg-trade-panel px-2 py-1 text-xs"><?php echo e($user->role); ?></span></td>
                    <td class="py-3 pr-4"><?php echo e($user->brokerAccount?->is_connected ? 'Connected' : '—'); ?></td>
                    <td class="py-3"><?php echo e($user->botSettings?->auto_trade ? 'Running' : 'Idle'); ?></td>
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </tbody>
    </table>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.trading', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /Users/vishal/Desktop/AutoTrade-FlatTrade/resources/views/admin/dashboard.blade.php ENDPATH**/ ?>