public static function surnameList($surnames, $style, $totals, ?ModuleListInterface $module, Tree $tree): string
    {
        $html = [];
        foreach ($surnames as $surn => $surns) {
            // Each surname links back to the indilist
            if ($module instanceof ModuleListInterface) {
                if ($surn) {
                    $url = $module->listUrl($tree, ['surname' => $surn]);
                } else {
                    $url = $module->listUrl($tree, ['alpha'  => ',']);
                }
            } else {
                $url = null;
            }

            // If all the surnames are just case variants, then merge them into one
            // Comment out this block if you want SMITH listed separately from Smith
            $tag = ($module instanceof ModuleListInterface) ? 'a' : 'span';
            $subhtml = '<' . $tag;
            if ($url !== null) {
                $subhtml .= ' href="' . e($url) . '"';
            }
            $subhtml .= ' dir="auto">' . e(implode(I18N::$list_separator, array_keys($surns))) . '</' . $tag . '>';
            
            if ($totals) {
                $subtotal = 0;
                foreach ($surns as $count) {
                    $subtotal += $count;
                }
                $subhtml .= '&nbsp;(' . I18N::number($subtotal) . ')';
            }
            $html[] = $subhtml;
        }
        switch ($style) {
            default:
            case 1:
                return '<ul><li>' . implode('</li><li>', $html) . '</li></ul>';
            case 2:
                return implode(I18N::$list_separator, $html);
            case 3:
                $i     = 0;
                $count = count($html);
                if ($count > 36) {
                    $col = 4;
                } elseif ($count > 18) {
                    $col = 3;
                } elseif ($count > 6) {
                    $col = 2;
                } else {
                    $col = 1;
                }
                $newcol = (int) ceil($count / $col);
                $html2  = '<table class="list_table"><tr>';
                $html2 .= '<td class="list_value" style="padding: 14px;">';

                foreach ($html as $surns) {
                    $html2 .= $surns . '<br>';
                    $i++;
                    if ($i === $newcol && $i < $count) {
                        $html2 .= '</td><td class="list_value" style="padding: 14px;">';
                        $newcol = $i + ceil($count / $col);
                    }
                }
                $html2 .= '</td></tr></table>';

                return $html2;
        }
    }