<?php
// Prevent direct access
if (count(get_included_files()) === 1) {
    http_response_code(403);
    exit('Forbidden');
}

// Página pública de chat web (canal para clientes sin WhatsApp).
// Resuelve el negocio por la clave pública de embed (?key=).
$key = trim($_GET['key'] ?? '');
$db = DB::connect();

$tenant = null;
if ($key !== '') {
    $stmt = $db->prepare("SELECT id, name, web_public_key FROM tenants WHERE web_public_key = :k AND deleted_at IS NULL LIMIT 1");
    $stmt->execute([':k' => $key]);
    $tenant = $stmt->fetch();
}

require dirname(__DIR__) . '/views/chat.php';
