bodyContent = $content;
$this->attributes = $attributes;
// Extract attributes using Helper
$this->variant = ComponentAttributeHelper::extractVariant($attributes, 'default');
$this->title = ComponentAttributeHelper::extractString($attributes, 'title');
$this->subtitle = ComponentAttributeHelper::extractString($attributes, 'subtitle');
$this->footer = ComponentAttributeHelper::extractString($attributes, 'footer');
$this->imageSrc = ComponentAttributeHelper::extractString($attributes, 'image-src');
$this->imageAlt = ComponentAttributeHelper::extractString($attributes, 'image-alt');
}
public function getRootNode(): Node
{
$div = new ElementNode('div');
// Build CSS classes using Helper
$additionalClasses = [];
if (isset($this->attributes['class']) && is_string($this->attributes['class'])) {
$additionalClasses[] = $this->attributes['class'];
}
$classes = ComponentClassBuilder::build('card', $this->variant, null, $additionalClasses);
$div->setAttribute('class', $classes);
// Apply additional attributes
$filteredAttributes = ComponentAttributeHelper::filterSpecialAttributes(
$this->attributes,
['title', 'subtitle', 'footer', 'image-src', 'image-alt']
);
foreach ($filteredAttributes as $key => $value) {
$div->setAttribute($key, (string)$value);
}
// Build complex nested content as HTML string
$contentHtml = $this->buildContent();
$div->appendChild(new TextNode($contentHtml));
return $div;
}
private function buildContent(): string
{
$elements = [];
// Image
if ($this->imageSrc !== null) {
$altAttr = $this->imageAlt !== null
? ' alt="' . htmlspecialchars($this->imageAlt) . '"'
: '';
$elements[] = '';
}
// Header (title + subtitle)
if ($this->title !== null || $this->subtitle !== null) {
$headerElements = [];
if ($this->title !== null) {
$headerElements[] = '
' . htmlspecialchars($this->subtitle) . '
'; } $elements[] = '