import { encodeOptions } from '../utils/options-encoder';
const mixin = (Base) => class _OfViewElement extends Base {
    connectedCallback() {
        if (!this.name || !this.uuid) {
            throw new Error('<of-view> Name or uuid attribute missing');
        }
        if (!this.src) {
            throw new Error(`<of-view> missing 'src' attribute.`);
        }
        if (!this.#iframe) {
            this.#iframe = document.createElement('iframe');
            this.#iframe.src = this.src;
            this.#iframe.style.height = '100%';
            this.#iframe.style.width = '100%';
            this.#iframe.setAttribute('name', encodeOptions({
                brokerUrl: this.brokerUrl,
                name: this.name,
                uuid: this.uuid,
                providerId: this.providerId,
                contextGroup: this.contextGroup
            }, 'of-frame'));
            this.#iframe.setAttribute('id', this.name);
            this.appendChild(this.#iframe);
        }
    }
    #iframe;
    get brokerUrl() {
        return this.getAttribute('of-broker');
    }
    set brokerUrl(val) {
        if (val) {
            this.setAttribute('of-broker', val);
        }
    }
    get name() {
        return this.getAttribute('of-name');
    }
    set name(val) {
        if (val) {
            this.setAttribute('of-name', val);
        }
    }
    get uuid() {
        return this.getAttribute('of-uuid');
    }
    set uuid(val) {
        if (val) {
            this.setAttribute('of-uuid', val);
        }
    }
    get src() {
        return this.getAttribute('src');
    }
    set src(val) {
        if (val) {
            this.setAttribute('src', val);
        }
    }
    get providerId() {
        return this.getAttribute('of-provider-id');
    }
    set providerId(val) {
        if (val) {
            this.setAttribute('of-provider-id', val);
        }
    }
    get contextGroup() {
        return this.getAttribute('of-context-group');
    }
    set contextGroup(val) {
        if (val) {
            this.setAttribute('of-context-group', val);
        }
    }
    static get observedAttributes() {
        return ['name'];
    }
};
export const registerOfViewElement = () => customElements.define('of-view', mixin(HTMLElement));
