<?php $pageTitle='Watchlist';require __DIR__.'/../lib/bootstrap.php';require_login(array('business'));if($_SERVER['REQUEST_METHOD']==='POST'&&verify_csrf()){db_exec('INSERT INTO rate_alerts(user_id,from_currency,to_currency,target_rate,direction,channel,active,created_at) VALUES(?,?,?,?,?,?,1,NOW())',array(user()['id'],$_POST['from_currency'],$_POST['to_currency'],(float)$_POST['target_rate'],$_POST['direction'],$_POST['channel']));flash('success','Alert created.');redirect('business/watchlist.php');}$rows=db_all('SELECT * FROM rate_alerts WHERE user_id=? ORDER BY id DESC',array(user()['id']));require __DIR__.'/../blocks/app-header.php';require __DIR__.'/../blocks/dashboard-open.php';?><div class="dash-head"><h1>Watchlist & alerts</h1></div><div class="grid grid-3"><div class="card form-card"><h3>Create alert</h3><form method="post"><?=csrf_field()?><div class="form-row"><div class="form-group"><label>From</label><input class="form-control" name="from_currency" value="USD" maxlength="3" required></div><div class="form-group"><label>To</label><input class="form-control" name="to_currency" value="NGN" maxlength="3" required></div></div><div class="form-group"><label>Target rate</label><input class="form-control" type="number" step="0.0001" name="target_rate" required></div><div class="form-row"><div class="form-group"><label>Trigger when</label><select class="form-control" name="direction"><option value="above">Rate is at or above</option><option value="below">Rate is at or below</option></select></div><div class="form-group"><label>Channel</label><select class="form-control" name="channel"><option>email</option><option>sms</option><option>whatsapp</option></select></div></div><button class="dark-btn">Save alert</button></form></div><div class="card" style="grid-column:span 2"><h3>Active alerts</h3><?php if(!$rows):?><p class="muted">No alerts yet.</p><?php endif;foreach($rows as $r):?><p><strong><?=e($r['from_currency'].' → '.$r['to_currency'])?></strong> <?=e($r['direction'])?> <?=e($r['target_rate'])?> via <?=e($r['channel'])?></p><?php endforeach;?></div></div><?php require __DIR__.'/../blocks/dashboard-close.php';require __DIR__.'/../blocks/app-footer.php';?>