<?php

declare(strict_types=1);

use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Module\IndividualListModule;
use Fisharebest\Webtrees\Module\ModuleListInterface;
use Fisharebest\Webtrees\Tree;

/**
 * @var IndividualListModule|null $module
 * @var array<string,string>      $params
 * @var array<array<int>>         $surnames
 * @var bool                      $totals
 * @var Tree                      $tree
 */

?>

<div class="wt-surnames-column-list px-3" style="columns: 15rem; column-rule: solid thin gray; border: solid thin gray;">
    <?php foreach ($surnames as $surn => $surns) : ?>
        <?php foreach ($surns as $surname => $count) : ?>
            <?php
            if ($surname === Individual::NOMEN_NESCIO) {
                $label = I18N::translateContext('Unknown surname', '…');
                $url   = $module instanceof ModuleListInterface ? $module->listUrl($tree, ['alpha' => '@'] + $params) : '';
            } elseif ($surname === '') {
                $label = e($surn);
                $url   = $module instanceof ModuleListInterface ? $module->listUrl($tree, ['surname' => $surn] + $params) : '';
            } else {
                $label = e($surname);
                $url   = $module instanceof ModuleListInterface ? $module->listUrl($tree, ['surname' => $surn] + $params) : '';
            }

            if ($totals) {
                $item = I18N::translate('%1$s (%2$s)', '<span class="ut">' . $label . '</span>', I18N::number($count));
            } else {
                $item = '<span class="ut">' . $label . '</span>';
            }
            ?>
            <div class="wt-surnames-column-list-item ut">
                <?php if ($url !== '') : ?>
                    <a href="<?= e($url) ?>"><?= $item ?></a>
                <?php else : ?>
                    <?= $item ?>
                <?php endif ?>
            </div>
        <?php endforeach ?>
    <?php endforeach ?>
</div>
