TenantAtlas/resources/views/filament/infolists/entries/normalized-settings.blade.php
2025-12-14 20:23:18 +01:00

122 lines
7.6 KiB
PHP

@php
$normalized = $getState() ?? [];
$warnings = $normalized['warnings'] ?? [];
$settings = $normalized['settings'] ?? [];
$settingsTable = $normalized['settings_table'] ?? null;
$settingsTableRows = is_array($settingsTable) ? ($settingsTable['rows'] ?? []) : [];
$context = $normalized['context'] ?? 'policy';
$recordId = $normalized['record_id'] ?? null;
@endphp
<div class="space-y-3">
@if (! empty($warnings))
<div class="rounded-md border border-amber-300 bg-amber-50 p-3 text-sm text-amber-800">
<div class="font-semibold">Warnings</div>
<ul class="mt-1 list-disc space-y-1 pl-5">
@foreach ($warnings as $warning)
<li>{{ $warning }}</li>
@endforeach
</ul>
</div>
@endif
@if (empty($settings) && empty($settingsTableRows))
<p class="text-sm text-gray-600">No settings available.</p>
@endif
@if (! empty($settingsTableRows))
<div class="space-y-2 rounded-md border border-gray-200 bg-white p-3 shadow-sm">
<div class="text-sm font-semibold text-gray-800">{{ is_array($settingsTable) ? ($settingsTable['title'] ?? 'Settings') : 'Settings' }}</div>
<livewire:settings-catalog-settings-table
:settings-rows="$settingsTableRows"
:context="$context"
:key="$recordId ? ('sc-settings-'.$context.'-'.$recordId) : ('sc-settings-'.$context)"
/>
</div>
@endif
@foreach ($settings as $block)
<div class="space-y-2 rounded-md border border-gray-200 bg-white p-3 shadow-sm">
<div class="text-sm font-semibold text-gray-800">{{ $block['title'] ?? 'Settings' }}</div>
@if (($block['type'] ?? 'keyValue') === 'table')
@php
$columns = $block['columns'] ?? null;
$hasColumns = is_array($columns) && ! empty($columns);
$columnMeta = [
'definitionId' => ['width' => 'w-[35%]', 'style' => 'width: 35%;', 'cell' => 'font-mono text-xs break-all whitespace-normal', 'cellStyle' => 'word-break: break-all; overflow-wrap: anywhere; white-space: normal;'],
'instanceType' => ['width' => 'w-[20%]', 'style' => 'width: 20%;', 'cell' => 'font-mono text-xs break-all whitespace-normal', 'cellStyle' => 'word-break: break-all; overflow-wrap: anywhere; white-space: normal;'],
'value' => ['width' => 'w-[25%]', 'style' => 'width: 25%;', 'cell' => 'break-words whitespace-pre-wrap', 'cellStyle' => 'overflow-wrap: anywhere; white-space: pre-wrap;'],
'path' => ['width' => 'w-[20%]', 'style' => 'width: 20%;', 'cell' => 'font-mono text-xs break-all whitespace-normal', 'cellStyle' => 'word-break: break-all; overflow-wrap: anywhere; white-space: normal;'],
];
@endphp
<div class="overflow-x-auto rounded-lg border border-gray-200" style="overflow-x: auto;">
<table class="min-w-[900px] w-full table-fixed text-left text-sm" style="table-layout: fixed; width: 100%; min-width: 900px;">
<thead class="bg-gray-50 text-gray-700">
<tr>
@if ($hasColumns)
@foreach ($columns as $column)
@php
$key = $column['key'] ?? null;
$meta = is_string($key) ? ($columnMeta[$key] ?? []) : [];
@endphp
<th class="px-3 py-2 {{ $meta['width'] ?? '' }}" style="{{ $meta['style'] ?? '' }}">{{ $column['label'] ?? $column['key'] ?? '-' }}</th>
@endforeach
@else
<th class="px-3 py-2">Path</th>
<th class="px-3 py-2">Value</th>
@endif
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
@foreach ($block['rows'] ?? [] as $row)
<tr>
@if ($hasColumns)
@foreach ($columns as $column)
@php
$key = $column['key'] ?? null;
$cell = is_string($key) ? ($row[$key] ?? null) : null;
$meta = is_string($key) ? ($columnMeta[$key] ?? []) : [];
@endphp
<td class="px-3 py-2 align-top text-gray-800 {{ $meta['cell'] ?? 'whitespace-pre-wrap' }}" style="{{ $meta['cellStyle'] ?? '' }}">
@if (is_array($cell))
<pre class="overflow-x-auto text-xs">{{ json_encode($cell, JSON_PRETTY_PRINT) }}</pre>
@elseif (is_bool($cell))
<span>{{ $cell ? 'true' : 'false' }}</span>
@else
<span title="{{ is_string($cell) ? $cell : '' }}">{{ $cell ?? '-' }}</span>
@endif
</td>
@endforeach
@else
<td class="px-3 py-2 align-top">
<div class="font-mono text-xs font-medium text-gray-800 break-all whitespace-normal" style="word-break: break-all; overflow-wrap: anywhere; white-space: normal;">{{ $row['path'] ?? '-' }}</div>
@if (! empty($row['label']))
<div class="text-xs text-gray-600">{{ $row['label'] }}</div>
@endif
</td>
<td class="px-3 py-2 align-top text-gray-800 break-words whitespace-pre-wrap" style="overflow-wrap: anywhere; white-space: pre-wrap;">
{{ is_array($row['value'] ?? null) ? json_encode($row['value'], JSON_PRETTY_PRINT) : ($row['value'] ?? '-') }}
</td>
@endif
</tr>
@endforeach
</tbody>
</table>
</div>
@else
<dl class="grid grid-cols-1 gap-3 sm:grid-cols-2">
@foreach ($block['entries'] ?? [] as $entry)
<div class="rounded border border-gray-100 bg-gray-50 p-3">
<dt class="text-xs uppercase tracking-wide text-gray-500">{{ $entry['key'] ?? '-' }}</dt>
<dd class="whitespace-pre-wrap text-sm text-gray-800">
{{ is_array($entry['value'] ?? null) ? json_encode($entry['value'], JSON_PRETTY_PRINT) : ($entry['value'] ?? '-') }}
</dd>
</div>
@endforeach
</dl>
@endif
</div>
@endforeach
</div>