<?php

namespace OtomaticAi\Content\Social;

use DOMDocument;
use DOMElement;
use OtomaticAi\Content\Contracts\ShouldDisplay;

class Instagram implements ShouldDisplay
{
    public $href;

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

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

        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);
    }
}
