@props([ 'column' => [], 'cell' => null, 'type' => null, 'value' => null, 'label' => null, 'url' => null, 'variant' => null, 'semantic' => null, 'formatted' => null, 'currency' => null, 'decimals' => null, 'fromRatio' => null, 'format' => null, 'context' => null, 'precision' => null, 'icon' => null, 'scaling' => null, ]) @php $cell = is_array($cell) ? $cell : (is_null($cell) ? [] : ['value' => $cell]); $cell = array_merge($cell, array_filter([ 'type' => $type, 'value' => $value, 'label' => $label, 'url' => $url, 'variant' => $variant, 'semantic' => $semantic, 'formatted' => $formatted, 'currency' => $currency, 'decimals' => $decimals, 'from_ratio' => $fromRatio, 'format' => $format, 'context' => $context, 'precision' => $precision, 'icon' => $icon, 'scaling' => $scaling, ], static fn ($item) => ! is_null($item))); $types = app(\Kview\UiData\TableCellTypeRegistry::class); $type = $types->normalize($cell['type'] ?? $column['type'] ?? 'text'); $value = $cell['value'] ?? null; $finance = app(\Kview\Visualization\FinanceFormatter::class); $presenter = app(\Kview\Visualization\TableCellPresenter::class); $semantic = $cell['semantic'] ?? $column['semantic'] ?? null; $label = array_key_exists('label', $cell) ? $cell['label'] : match ($type) { 'status' => $presenter->statusLabel($value, $semantic), 'label', 'tag' => $semantic === 'currency' ? $finance->displayCurrency($value) : $finance->label($value), default => $value, }; $variant = $presenter->variant( $type, $value, $cell['variant'] ?? $column['variant'] ?? null, $semantic, ); $titleValue = in_array($type, ['text', 'entity', 'link', 'label'], true) ? (is_scalar($label) ? trim(strip_tags((string) $label)) : '') : ''; @endphp @switch($type) @case('entity') @case('link') @if (! empty($cell['url'])) {{ $label ?: '-' }} @else {{ $label ?: '-' }} @endif @break @case('tag') {{ $label ?: '-' }} @break @case('status') {{ $label ?: '-' }} @break @case('multiselect') @forelse ((array) $value as $item) @php $itemLabel = is_array($item) ? ($item['label'] ?? $item['value'] ?? '') : $item; $itemVariant = is_array($item) ? ($item['variant'] ?? 'default') : 'default'; @endphp {{ $itemLabel }} @empty - @endforelse @break @case('currency') @php $currency = $cell['currency'] ?? $column['currency'] ?? 'EUR'; $decimals = $cell['decimals'] ?? $column['decimals'] ?? 2; @endphp {{ $finance->amount($value, $currency, $decimals) }} @break @case('amount') @php $amountCurrency = $cell['currency'] ?? $column['currency'] ?? null; $amountScaling = $cell['scaling'] ?? $column['scaling'] ?? null; @endphp {{ $cell['formatted'] ?? $finance->scaledAmount($value, $amountCurrency, $amountScaling) }} @break @case('number') @php $decimals = $cell['decimals'] ?? $column['decimals'] ?? 0; $formatted = $cell['formatted'] ?? null; @endphp {{ filled($formatted) ? $formatted : $finance->number($value, $decimals) }} @break @case('scaled-number') {{ $cell['formatted'] ?? $finance->scaledNumber($value, $cell['scaling'] ?? $column['scaling'] ?? null) }} @break @case('percentage') @php $decimals = $cell['decimals'] ?? $column['decimals'] ?? 1; $fromRatioValue = $cell['from_ratio'] ?? $column['from_ratio'] ?? true; $fromRatio = filter_var($fromRatioValue, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? true; @endphp {{ $fromRatio ? $finance->percent($value, $decimals) : $finance->percentPoint($value, $decimals) }} @break @case('multiple') @php $decimals = $cell['decimals'] ?? $column['decimals'] ?? 2; @endphp {{ $finance->multiple($value, $decimals) }} @break @case('quarter') {{ $finance->quarter($value) }} @break @case('year') {{ $finance->year($value) }} @break @case('label') {{ $finance->label($value) }} @break @case('date') @break @case('boolean') @break @case('sparkline') @php $values = collect((array) $value)->filter(fn ($item) => is_numeric($item))->values(); $min = $values->min() ?? 0; $max = $values->max() ?? 0; $range = max(1, $max - $min); $count = max(1, $values->count() - 1); $points = $values->map(function ($item, $index) use ($min, $range, $count) { $x = ($index / $count) * 96; $y = 26 - ((($item - $min) / $range) * 22); return round($x, 2).','.round($y, 2); })->implode(' '); @endphp @if ($values->isNotEmpty()) @else - @endif @break @default {{ filled($label) ? $label : '-' }} @endswitch