schema([ TextEntry::make('comparison') ->hiddenLabel() ->html() ->state(function (DataChangeRequest $record): string { $old = $record->old_data ?? []; $new = $record->new_data ?? []; if (! is_array($old) || ! is_array($new)) { return 'Format data tidak valid.'; } $renderValue = function ($value) { if (empty($value)) { return 'Kosong'; } $paths = is_array($value) ? $value : [$value]; $isProbablyPath = false; foreach ($paths as $path) { if (is_string($path) && (str_contains($path, '/') || str_contains($path, '\\'))) { $isProbablyPath = true; break; } } if ($isProbablyPath) { return collect($paths) ->map(function ($path) { if (! is_string($path)) { return e(json_encode($path)); } $url = Storage::disk(config('filesystems.default'))->url($path); $extension = strtolower(pathinfo($path, PATHINFO_EXTENSION)); if (in_array($extension, ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'])) { return ""; } if ($extension === 'pdf') { return "
↗️ Buka PDF di Tab Baru
"; } return "📎 Buka Dokumen (".strtoupper($extension).')'; }) ->implode('
'); } return e(is_scalar($value) ? $value : json_encode($value)); }; // 1. Deletion Request if (isset($new['__delete_request__']) && $new['__delete_request__'] === true) { return "
".CheerfulNotification::getByKey('data_change.deletion_request_title')."

".CheerfulNotification::getByKey('data_change.deletion_request_desc').'

'; } // 2. New Addition Request if (empty($old)) { $rows = collect($new) ->map(function ($value, $key) use ($renderValue) { return sprintf( "
%s
[BARU]
%s
", e($key), $renderValue($value) ); }) ->implode(''); return "
".CheerfulNotification::getByKey('data_change.addition_request_title')."

".CheerfulNotification::getByKey('data_change.addition_request_desc')."

{$rows} "; } // 3. Standard Comparison (Update) return collect($new) ->map(function ($newValue, $key) use ($old, $renderValue) { $oldValue = $old[$key] ?? null; if ($oldValue === $newValue) { return null; } return sprintf( "
%s
LAMA
%s
BARU
%s
", e($key), $renderValue($oldValue), $renderValue($newValue) ); }) ->filter() ->implode(''); }) ->columnSpanFull(), ]) ->columns(1); } }