<?php
// pages/components/module_uninstall_confirm.php
use Components\Router;
use Components\Base;
use Components\ModuleLoader;
use Components\Button;

$module = mh_get('module', '', 'key');
if ($module === '' || !ModuleLoader::exists($module)) {
    echo '<div class="p-4 text-red-600">Module not found.</div>';
    return;
}

$title = ModuleLoader::title($module);

$persist = [];
foreach (['drawer', 'return', 'keys', 'autoclose', 'target'] as $p) {
    $v = mh_get($p, null);
    if ($v !== null) $persist[$p] = $v;
}

// The actual removal is handled by POSTing to save_module_config with remove=1
$hxPost = Router::url('save_module_config', array_merge(['module' => $module, 'remove' => 1, 'partial' => 1], $persist));

ob_start();
?>
    <div class="space-y-4">
        <p class="text-sm text-gray-500">
            <?= sprintf(\mh_lng('UI_CONFIRM_UNINSTALL_DESC', 'This will remove the configuration and data for the module "%s". This action cannot be undone.'), Base::h($title)); ?>
        </p>

        <template x-teleport="#confirm-modal-footer">
            <div class="grid grid-cols-1 sm:grid-cols-2 gap-3 w-full">
                <?= Button::render(\mh_lng('UI_CANCEL', 'Cancel'), [
                        'variant' => 'outline',
                        'fullWidth' => true,
                        'attrs' => [
                                'command' => 'close',
                                'commandfor' => 'confirm-modal',
                        ],
                ]) ?>

                <?= Button::render(\mh_lng('UI_UNINSTALL', 'Uninstall'), [
                        'variant' => 'danger',
                        'fullWidth' => true,
                        'attrs' => [
                                'hx-post' => $hxPost,
                                'hx-target' => 'body',
                                'hx-swap' => 'beforeend',
                        ],
                ]) ?>
            </div>
        </template>
    </div>
<?php
$html = ob_get_clean();
echo $html;
