icon === null) { return null; } if ($this->icon instanceof Icon) { return $this->icon; } return Icon::fromString($this->icon); } public static function fromArray(array $data): self { return new self( name: $data['name'] ?? '', url: $data['url'] ?? '', icon: $data['icon'] ?? null, // Can be string or Icon isActive: $data['is_active'] ?? false ); } public function toArray(): array { $icon = $this->getIcon(); return [ 'name' => $this->name, 'url' => $this->url, 'icon' => $this->icon instanceof Icon ? $this->icon->toString() : $this->icon, 'icon_html' => $icon?->toHtml('admin-nav__icon') ?? '', 'is_active' => $this->isActive, ]; } public function withActiveState(bool $isActive): self { return new self( name: $this->name, url: $this->url, icon: $this->icon, isActive: $isActive ); } public function isActive(string $currentPath): bool { return $this->url === $currentPath || str_starts_with($currentPath, $this->url); } }