<?php
// pages/components/trigger_module_route.php
// Route handler to render a single trigger module card by key

if (!defined('BEEZUI_ROOT')) {
    define('BEEZUI_ROOT', dirname(__DIR__, 2)); // pages/components => root
}

require_once BEEZUI_ROOT . '/vendor/autoload.php';
require_once BEEZUI_ROOT . '/components/Autoload.php';
require_once BEEZUI_ROOT . '/components/index.php';

use Components\ModuleLoader;
use Components\Base;
use Components\ConfigStore;


$key = mh_get('module', '', 'key');
if ($key === '') {
    http_response_code(400);
    echo '<div class="text-sm text-red-600">Missing module key</div>';
    return;
}

$flowOnly = (mh_get('flow_only', 0, 'int') === 1);

if ($flowOnly) {
    $modKey = $key;
    $isOn = ConfigStore::isModuleOn($modKey);
    $m = ['key' => $modKey];
    include __DIR__ . '/trigger_module_flow.php';
    return;
}

$m = ModuleLoader::campaignByKey($key);

if (!$m) {
    http_response_code(404);
    echo '<div class="text-sm text-red-600">Unknown module: ' . Base::h($key) . '</div>';
    return;
}

// Reuse the generic partial that expects $m in scope
include __DIR__ . '/trigger_module.php';
