return function () {
$self = url('/@object/@action/' . urlencode('db/demo_data'));
$demo = _class('docs')->_sample('demo_data');
$p = $demo->params($_GET);
$rows = $demo->rows($p);
$h = fn ($v) => _prepare_html((string) $v, 0);
$intro = '<p class="docs-demo-intro">The text generator of <b>Demo data</b> (admin Tools / Demo data, console <code>demo:seed</code>): the rows a
source would write, made here in memory for the seed and language you choose; nothing is written to a database. Every value comes from
fixed word, name and city lists (English, Ukrainian, German, Latin lorem) through a seeded generator, so a seed always gives the same rows;
HTML columns get the same plain text inside a fixed <code><p></code> template. Addresses end in <code>example.invalid</code>,
phone numbers are in the 555-01xx block and IPs in 192.0.2.0/24, all reserved for examples. On a site the admin module writes such
rows only where a super-admin approves them, lists each one in a ledger and removes exactly those rows again.
Classes: <code>yf_demo_seed</code>, <code>yf_demo_seed_text</code>, <code>yf_demo_seed_sources</code>.</p>';
$select = function ($name, array $options, $selected, $label) use ($h) {
$html = '<select name="' . $name . '" class="form-control form-select input-sm form-select-sm" aria-label="' . $h($label) . '">';
foreach ($options as $value => $text) {
$html .= '<option value="' . $h($value) . '"' . ((string) $value === (string) $selected ? ' selected' : '') . '>' . $h($text) . '</option>';
}
return $html . '</select>';
};
$sources = [];
foreach ($demo->SOURCES as $s) {
$sources[$s] = $demo->title($s);
}
$form = '<form method="get" action="' . $self . '" class="docs-demo-data-form">'
. $select('source', $sources, $p['source'], 'Source') . $select('locale', $demo->LOCALES, $p['locale'], 'Language')
. '<input type="number" name="seed" min="1" max="99999" value="' . (int) $p['seed'] . '" class="form-control input-sm form-control-sm" aria-label="Seed">'
. $select('units', [1 => '1 unit', 2 => '2 units', 3 => '3 units', 4 => '4 units', 5 => '5 units'], $p['units'], 'Units')
. '<button type="submit" class="btn btn-primary btn-sm">Generate</button></form>';
$out = '';
foreach ($rows as $e) {
$cells = '';
foreach ($e['row'] as $k => $v) {
$v = is_scalar($v) ? (string) $v : '';
$cells .= '<tr><th>' . $h($k) . '</th><td>' . $h(mb_strlen($v) > 200 ? mb_substr($v, 0, 200) . '…' : $v) . '</td></tr>';
}
$out .= '<div class="docs-demo-data-row"><div class="text-muted small">' . $h($e['table']) . '</div><table class="table table-condensed table-sm">' . $cells . '</table></div>';
}
css('.docs-demo-data-form { display:flex; flex-wrap:wrap; gap:6px; align-items:center; margin-bottom:12px; } .docs-demo-data-form .form-control, .docs-demo-data-form .form-select { width:auto; }'
. ' .docs-demo-data-rows { display:grid; grid-template-columns:repeat(auto-fill, minmax(340px, 1fr)); gap:10px; }'
. ' .docs-demo-data-row { border:1px solid rgba(128,128,128,.3); border-radius:6px; padding:4px 8px; min-width:0; overflow-wrap:anywhere; } .docs-demo-data-row th { width:28%; }');
return $intro . $form . '<div class="docs-demo-data-rows" id="docs-demo-data-rows">' . ($out ?: '<p>No rows.</p>') . '</div>';
};