<?php

declare(strict_types=1);

final class Modal
{
    public static function render(string $id, string $title, string $bodyHtml): string
    {
        ob_start();
        ?>
        <div id="<?= e($id) ?>" class="fixed inset-0 hidden items-center justify-center bg-black/40 p-4">
            <div class="w-full max-w-lg rounded-xl bg-white p-6 shadow">
                <div class="flex items-center justify-between">
                    <h3 class="text-base font-semibold"><?= e($title) ?></h3>
                    <button type="button" class="rounded-lg border px-2 py-1 text-sm" onclick="document.getElementById('<?= e($id) ?>').classList.add('hidden')">Close</button>
                </div>
                <div class="mt-4 text-sm text-slate-700">
                    <?= $bodyHtml ?>
                </div>
            </div>
        </div>
        <?php
        return (string)ob_get_clean();
    }
}
