<?php
// delete.php
declare(strict_types=1);
require_once dirname(__DIR__,2).'/config/functions.php';
require_role(['Admin','Ops']);
if($_SERVER['REQUEST_METHOD']!=='POST') redirect('list.php');
try{
  csrf_verify((string)($_POST['csrf'] ?? ''));
  $id=(int)($_POST['id'] ?? 0); if($id<=0) redirect('list.php');
  $cid=current_user()['company_id'] ?? null; if(!$cid) redirect(url_public('index.php'));
  $del=db()->prepare("DELETE FROM vehicles WHERE id=:id AND company_id=:cid");
  $del->execute([':id'=>$id, ':cid'=>$cid]);
  audit_log('vehicle.delete','vehicle',$id,null);
}catch(Throwable $e){}
redirect('list.php');
