@props([ 'itemData' => null, // For sub_items objects 'type' => null, // From DB column or manual prop 'redirect' => null, // From DB column or manual prop 'label' => null, // Already translated string ]) @php /** * DATA NORMALIZATION * If 'itemData' is passed (from sub_items), extract its internal structure. */ $finalType = $type; $rawRedirect = $redirect; if ($itemData) { $rawRedirect = $itemData['redirect'] ?? null; $finalType = $itemData['type'] ?? $finalType; } /** * VALUE EXTRACTION * Handle cases where the redirect is an object (common in sub_items JSON). */ if (is_array($rawRedirect)) { $redirectValue = $rawRedirect['value'] ?? 'javascript:void(0)'; $finalType = $rawRedirect['type'] ?? $finalType; } else { $redirectValue = $rawRedirect ?? 'javascript:void(0)'; } // Default output variables $href = 'javascript:void(0)'; $target = '_self'; $rel = ''; /** * URL GENERATION LOGIC */ if ($finalType === 'internal_slug' || $finalType === 'internal') { // Internal links may be a catalogue reference ("slug:42") instead of a literal path: // slug_path() resolves it to the content's CURRENT path, so renaming a slug never breaks // the link (docs/CLAUDE-SLUGS-CATALOGO.md). A literal path passes straight through, and // null means the referenced content is gone — better an inert link than a wrong one. $resolvedPath = slug_path((string) $redirectValue); $href = $resolvedPath === null ? 'javascript:void(0)' : url($resolvedPath); } else { // Direct value for 'url', 'contact_link', 'anchor', etc. $href = (string) $redirectValue; if ($finalType === 'url') { $target = '_blank'; $rel = 'noopener noreferrer'; } } @endphp merge(['class' => '']) }}> @if (!$slot->isEmpty()) {{ $slot }} @elseif ($label) {{ $label }} @endif