<?php
declare(strict_types=1);
require_once __DIR__ . '/../app/bootstrap.php';
use App\Core\Auth;use App\Core\Database;use App\Core\PosService;
Auth::requireRole(['vendor','admin','staff'],'public/login.php');
$panelType='vendor';$pageTitle='Pro POS | Vendor Panel';$vendorId=PosService::currentVendorId();
$products=PosService::searchProducts('', $vendorId, 8);$registers=PosService::registers($vendorId);
$today=Database::safeFetchOne('SELECT COUNT(*) sales_count,COALESCE(SUM(total_amount),0) revenue FROM pos_sales WHERE vendor_id=? AND DATE(created_at)=CURDATE()',[$vendorId]);
$staff=db_count('pos_staff_assignments','vendor_id=? AND status="active"',[$vendorId]);$queue=db_count('pos_sync_queue','status="pending"');
require ROOT_PATH.'/app/Layouts/panel_header.php';
?>
<div class="d-flex justify-content-between align-items-start flex-wrap gap-3 mb-3"><div><h1 class="h3 mb-1">Vendor Pro POS</h1><p class="text-muted mb-0">Browser POS with barcode scanning, shifts, receipts, refunds and synchronized stock.</p></div><a class="btn btn-primary btn-lg" href="<?= url('pos/register.php'.($vendorId?'?vendor_id='.$vendorId:'')) ?>" target="_blank">Launch POS Register</a></div>
<div class="row g-3 mb-4"><div class="col-md-3"><div class="stat-tile"><div class="small text-muted">Today POS Sales</div><strong><?= (int)($today['sales_count']??0) ?></strong></div></div><div class="col-md-3"><div class="stat-tile"><div class="small text-muted">Today POS Revenue</div><strong><?= money($today['revenue']??0) ?></strong></div></div><div class="col-md-3"><div class="stat-tile"><div class="small text-muted">Active POS Staff</div><strong><?= $staff ?></strong></div></div><div class="col-md-3"><div class="stat-tile"><div class="small text-muted">Offline Queue</div><strong><?= $queue ?> pending</strong></div></div></div>
<div class="row g-4"><div class="col-lg-8"><div class="card module-card"><div class="card-header bg-white"><strong>POS registers</strong></div><div class="table-responsive"><table class="table align-middle mb-0"><thead><tr><th>Register</th><th>Code</th><th>Receipt</th><th>Printer</th><th>Status</th><th></th></tr></thead><tbody><?php if(!$registers): ?><?= table_empty(6,'No POS registers configured.') ?><?php endif; ?><?php foreach($registers as $r): ?><tr><td><?= e($r['name']) ?></td><td><?= e($r['register_code']) ?></td><td><?= e($r['receipt_width']) ?></td><td><?= e($r['printer_type']) ?></td><td><?= badge($r['status']) ?></td><td><a class="btn btn-sm btn-primary" href="<?= url('pos/register.php?register_id='.(int)$r['id']) ?>">Open</a></td></tr><?php endforeach; ?></tbody></table></div></div></div><div class="col-lg-4"><div class="card module-card"><div class="card-header bg-white"><strong>POS operations</strong></div><div class="list-group list-group-flush"><a class="list-group-item" href="<?= url('pos/settings.php') ?>">Registers & Settings</a><a class="list-group-item" href="<?= url('vendor/pos-staff.php') ?>">POS Staff Roles</a><a class="list-group-item" href="<?= url('pos/shifts.php') ?>">Shift / Cash Drawer</a><a class="list-group-item" href="<?= url('pos/reports.php') ?>">X/Z Reports</a><a class="list-group-item" href="<?= url('pos/refunds.php') ?>">Refunds</a><a class="list-group-item" href="<?= url('pos/print-labels.php') ?>">Barcode Labels</a></div></div></div></div>
<div class="card module-card mt-4"><div class="card-header bg-white"><strong>Available POS products</strong></div><div class="table-responsive"><table class="table mb-0"><thead><tr><th>Product</th><th>SKU</th><th>Barcode</th><th>Price</th><th>Stock</th></tr></thead><tbody><?php if(!$products): ?><?= table_empty(5,'No published products available for POS.') ?><?php endif; ?><?php foreach($products as $p): ?><tr><td><?= e($p['name']) ?></td><td><?= e($p['sku']) ?></td><td><code><?= e($p['barcode']) ?></code></td><td><?= money($p['sale_price']?:$p['regular_price']) ?></td><td><?= (int)$p['stock'] ?></td></tr><?php endforeach; ?></tbody></table></div></div>
<?php require ROOT_PATH.'/app/Layouts/panel_footer.php'; ?>
