import { debounceEvent } from '../../utils/utils';
/**
 * @internal
 * This is an internal component
 */
export class Observer {
    constructor() {
        this.observer = new MutationObserver(this.onChange.bind(this));
        /**
         * Watch attributes
         */
        this.incattrs = true;
        /**
         * How long to delay the event
         */
        this.debounce = 0;
    }
    connectedCallback() {
        if (this.debounce) {
            this.anjContentChange = debounceEvent(this.anjContentChange, this.debounce);
        }
        this.observer.observe(this.element, { attributes: this.incattrs, childList: true, subtree: true });
    }
    disconnectedCallback() {
        this.observer.disconnect();
    }
    onChange(mutations) {
        this.anjContentChange.emit(mutations);
    }
    static get is() { return "anj-observer"; }
    static get properties() { return {
        "incattrs": {
            "type": "boolean",
            "mutable": false,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Watch attributes"
            },
            "attribute": "incattrs",
            "reflect": false,
            "defaultValue": "true"
        },
        "debounce": {
            "type": "number",
            "mutable": false,
            "complexType": {
                "original": "number",
                "resolved": "number",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "How long to delay the event"
            },
            "attribute": "debounce",
            "reflect": false,
            "defaultValue": "0"
        }
    }; }
    static get events() { return [{
            "method": "anjContentChange",
            "name": "anjContentChange",
            "bubbles": true,
            "cancelable": true,
            "composed": true,
            "docs": {
                "tags": [],
                "text": "Fires when the content changes"
            },
            "complexType": {
                "original": "MutationRecord[]",
                "resolved": "MutationRecord[]",
                "references": {
                    "MutationRecord": {
                        "location": "global"
                    }
                }
            }
        }]; }
    static get elementRef() { return "element"; }
}
