<?php
require_once __DIR__.'/../inc/config.php'; require_once __DIR__.'/../inc/db.php'; header('Content-Type: application/json');
$paid=(int)db()->query("SELECT COUNT(*) c FROM orders WHERE status IN ('Paid','Shipped')")->fetch()['c'];
$rev=(float)db()->query("SELECT IFNULL(SUM(amount),0) s FROM orders WHERE status IN ('Paid','Shipped')")->fetch()['s'];
$aov=$paid?round($rev/$paid,2):0;
$suggest=[
  'headline' => [
    'A' => 'Air Vanilla Blue Viral – Sekali Pandang Terus Beli',
    'B' => 'Mula Niaga Air Balang – Modal Kecil, Rasa Premium'
  ],
  'bump_price' => max(3.0, min(8.0, $aov*0.12)),
  'upsell_price' => max(7.0, min(15.0, $aov*0.25))
];
echo json_encode(['ok'=>true,'suggest'=>$suggest,'aov'=>$aov]);