/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { emitEvent, toggleAttribute } from '@tylertech/forge-core';
export class BaseAdapter {
    constructor(_component) {
        this._component = _component;
    }
    get hostElement() {
        return this._component;
    }
    getHostAttribute(name) {
        return this._component.getAttribute(name);
    }
    setHostAttribute(name, value = '') {
        this._component.setAttribute(name, value);
    }
    removeHostAttribute(name) {
        this._component.removeAttribute(name);
    }
    toggleHostAttribute(name, hasAttribute, value) {
        toggleAttribute(this._component, hasAttribute, name, value);
    }
    emitHostEvent(type, data = null, bubble = true, cancelable) {
        return emitEvent(this._component, type, data, bubble, cancelable);
    }
    addHostListener(event, callback, options) {
        this._component.addEventListener(event, callback, options);
    }
    removeHostListener(event, callback) {
        this._component.removeEventListener(event, callback);
    }
    addWindowListener(event, callback, options) {
        window.addEventListener(event, callback, options);
    }
    removeWindowListener(event, callback, options) {
        window.removeEventListener(event, callback, options);
    }
    addDocumentListener(event, callback, options) {
        document.addEventListener(event, callback, options);
    }
    removeDocumentListener(event, callback, options) {
        document.removeEventListener(event, callback, options);
    }
    getScreenWidth() {
        return window.innerWidth;
    }
    setBodyAttribute(name, value) {
        document.body.setAttribute(name, value);
    }
    removeBodyAttribute(name) {
        document.body.removeAttribute(name);
    }
    get isConnected() {
        return this._component.isConnected;
    }
    redispatchEvent(event, options) {
        var _a, _b, _c, _d, _e;
        const isFromLightDom = !(((_a = event.target) === null || _a === void 0 ? void 0 : _a.getRootNode()) instanceof ShadowRoot);
        if (event.bubbles && (event.composed || isFromLightDom)) {
            event.stopPropagation();
        }
        const eventCopy = Object.assign(Object.assign({}, event), { detail: (_b = event.detail) !== null && _b !== void 0 ? _b : null, bubbles: (_c = options === null || options === void 0 ? void 0 : options.bubbles) !== null && _c !== void 0 ? _c : event.bubbles, cancelable: (_d = options === null || options === void 0 ? void 0 : options.cancelable) !== null && _d !== void 0 ? _d : event.cancelable, composed: (_e = options === null || options === void 0 ? void 0 : options.composed) !== null && _e !== void 0 ? _e : event.composed });
        const newEvent = Reflect.construct(event.constructor, [event.type, eventCopy]);
        const isCancelled = !this._component.dispatchEvent(newEvent);
        if (isCancelled) {
            event.preventDefault();
        }
        return !isCancelled;
    }
}
