<?php

declare(strict_types=1);

namespace App\Framework\View\Dom;

final class TextNode implements Node
{
    use NodeTrait {
        getTextContent as private getTextContentFromChildren;
    }

    public function __construct(
        private string $text
    ) {}

    public function getNodeType(): NodeType
    {
        return NodeType::TEXT;
    }

    public function getNodeName(): string
    {
        return '#text';
    }

    public function getTextContent(): string
    {
        return $this->text;
    }

    public function setText(string $text): void
    {
        $this->text = $text;
    }

    public function accept(NodeVisitor $visitor): void
    {
        $visitor->visitText($this);
    }

    public function clone(): Node
    {
        return new self($this->text);
    }
}
