<?php

namespace OtomaticAi\Content\Social;

use DOMDocument;
use DOMElement;
use OtomaticAi\Content\Contracts\ShouldDisplay;
use OtomaticAi\Vendors\Illuminate\Support\Arr;

class Tiktok implements ShouldDisplay
{
    public $href;

    public function __construct($href)
    {
        $this->href = $href;
    }

    public function toHtmlElement(DOMDocument $document): ?DOMElement
    {
        $el = $document->createElement("ototiktok");
        $el->setAttribute("href", $this->href);
        $el->setAttribute("uid", uniqid("tiktok-"));

        return $el;
    }

    public function toDisplayElement(DOMElement $node): ?DOMElement
    {
        return $this->toHtmlElement($node->ownerDocument);
    }

    static public function fromHtmlElement(DOMElement $node)
    {
        $href = $node->getAttribute("href");

        return new self($href);
    }
}
