"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Semifunctional_1 = require("../../../../../Class/Semifunctional");
const _ids_1 = require("../../../../_ids");
const globalComponent_1 = require("../../../../globalComponent");
class SizeObserver extends Semifunctional_1.Semifunctional {
    constructor(system) {
        super({
            fi: ['component'],
            fo: [],
            i: [],
            o: ['width', 'height'],
        }, {
            input: {
                component: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_SIZE_OBSERVER);
    }
    f({ component }, done) {
        const { api: { document: { ResizeObserver }, }, } = this.__system;
        const globalId = component.getGlobalId();
        let _component = (0, globalComponent_1.getGlobalComponent)(this.__system, globalId);
        const setup = (_next_component) => {
            if (!this._observer) {
                const observer_callback = (entries) => {
                    const entry = entries[0];
                    const { width, height } = entry.contentRect;
                    this._output.width.push(width);
                    this._output.height.push(height);
                };
                const observer = new ResizeObserver(observer_callback);
                this._observer = observer;
            }
            if (_component) {
                this._observer.unobserve(_component.$element);
            }
            _component = _next_component;
            const { $element } = _component;
            // this._observer.observe($element)
        };
        if (_component) {
            setup(_component);
        }
        const unlisten_global = (0, globalComponent_1.listenGlobalComponent)(this.__system, globalId, (_component) => {
            setup(_component);
        });
    }
    d() {
        // TODO
    }
}
exports.default = SizeObserver;
//# sourceMappingURL=index.js.map