@use('App\Support\CharityPresenter') @use('App\Models\ColumnTooltip') @props([ 'charity', 'columns', 'borderStartKey', 'borderEndKey', 'pinLeftKey' => null, 'pinRightKeys' => [], 'barMaxima' => [], 'values' => [], 'openRows' => [], 'detailEnabled' => true, ]) @php // Columns are data, not code: each one carries a renderer (how it is drawn) // and, for everything but the name cell, an expression that Services\ // HomepageColumns has already compiled into the query. `$values` holds // those computed results for this row, keyed by column key — a new column // is a row in column_tooltips and needs no change here. $words = preg_split('/\s+/', $charity->name ?? ''); $initials = implode('', array_map( fn($w) => mb_strtoupper(mb_substr($w, 0, 1)), array_slice(array_filter($words), 0, 2) )); $rowId = $charity->id ?? $charity->registration_number ?? $charity->ein; $detailUrl = route('charity.detail', [ 'country' => strtolower($charity->country_code ?? 'us'), 'registration_number' => $charity->registration_number ?? $charity->ein, ]); $pinClass = function (string $key) use ($pinLeftKey, $pinRightKeys): string { if ($key === $pinLeftKey) return ' col-pin-l'; if (in_array($key, $pinRightKeys, true)) return ' col-pin-r'; return ''; }; @endphp {{-- `detailEnabled` is the Customizer's Features switch. When it is off there is no expander to click, so a row can only be open because it was open before the switch was thrown — treating it as closed keeps the panel from surviving its own button. --}} @php $isOpen = $detailEnabled && in_array((string) $rowId, array_map('strval', $openRows), true); @endphp @foreach ($columns as $col) @php $key = $col->column_key; $groupClass = ($key === $borderStartKey ? ' col-group-start' : '') . ($key === $borderEndKey ? ' col-group-end' : '') . $pinClass($key); // Raw for the text renderer, coerced for everything that draws a // number, a badge or a bar. $value = $values[$key] ?? null; $number = is_numeric($value) ? $value + 0 : null; // The bar is scaled against the largest value on screen, so it // compares the charities the visitor is actually looking at. $barPercent = $col->show_bar ? CharityPresenter::barPercent($number, $barMaxima[$key] ?? null) : null; // Unknown renderer falls back rather than rendering nothing. $renderer = array_key_exists($col->renderer, ColumnTooltip::RENDERERS) ? $col->renderer : 'figure'; @endphp {{-- One partial per renderer; the renderer whitelist above keeps an unknown value from reaching the view name. --}} @include('components.columns.' . $renderer) @endforeach {{-- Rendered only when open — see the note on ⚡homepage's $openRows. Nothing of the panel is sent ahead of time, so switching the feature off removes the whole thing and not just its button. The inner panel is position:sticky so it stays within the visible width when the table itself is scrolled sideways. --}} @if ($isOpen) @endif