typeof process !== 'undefined' &&
    process.env &&
    "production" === 'test';
function initializeTracking() {
    (function (t, r, _kk, n, pp) {
        if (typeof window.btntConfig !== "object") {
            window.btntConfig = {
                domain: "https://ssgtm.infineon.com",
                withCookies: true,
                maxBatchSize: 10
            };
        }
        if (window["btnt"])
            return;
        window["btnt"] = function (z) {
            if (typeof z !== "object") {
                z = {};
            }
            if (typeof window.btntQueue !== "object") {
                window.btntQueue = [];
            }
            window.btntQueue.push(z);
        };
        n = t.createElement(r);
        // Add safety check for test environments
        pp = t.getElementsByTagName(r)[0];
        if (pp && pp.parentNode) {
            n.async = 1;
            n.src = window.btntConfig.domain + "/btnt.js";
            pp.parentNode.insertBefore(n, pp);
        }
    })(document, "script");
}
function trackComponent(componentName, environment) {
    const skipEnvironments = ['jest', 'localhost', 'error'];
    if (skipEnvironments.includes(environment)) {
        return;
    }
    if (!window.INFINEON_TRACKED_COMPONENTS) {
        window.INFINEON_TRACKED_COMPONENTS = new Set();
    }
    if (window.INFINEON_TRACKED_COMPONENTS.has(componentName)) {
        return;
    }
    window.INFINEON_TRACKED_COMPONENTS.add(componentName);
    if (!window.btnt)
        initializeTracking();
    window.btnt({
        event_name: "component_initialized",
        component_name: componentName,
        environment: environment
    });
}

const isNestedInIfxComponent = (el) => {
    let parent = el.parentNode;
    while (parent) {
        if (parent instanceof ShadowRoot) {
            parent = parent.host;
            continue;
        }
        if (parent instanceof HTMLElement && parent.tagName.toLowerCase().startsWith('ifx')) {
            return true;
        }
        parent = parent.parentNode;
    }
    return false;
};

const waitForDOMReady = () => {
    return new Promise((resolve) => {
        if (document.readyState === 'complete' || document.readyState === 'interactive') {
            resolve();
        }
        else {
            const onReady = () => {
                resolve();
                document.removeEventListener('DOMContentLoaded', onReady);
            };
            document.addEventListener('DOMContentLoaded', onReady);
        }
    });
};

let frameworkCache = null;
const detectFramework = async () => {
    if (frameworkCache)
        return frameworkCache;
    if (typeof window === 'undefined' || typeof document === 'undefined') {
        frameworkCache = 'non-browser';
        return frameworkCache;
    }
    const win = window;
    const doc = document;
    typeof process !== 'undefined' &&
        process.env &&
        "production" === 'test';
    const isStorybook = win.location.search.includes('viewMode') ||
        win.location.href.includes('viewMode') ||
        win.__STORYBOOK_ENV__;
    if (isStorybook) {
        frameworkCache = 'Storybook';
        return frameworkCache;
    }
    const isLocalhost = ['localhost', '127.0.0.1'].includes(win.location.hostname);
    if (isLocalhost) {
        frameworkCache = 'localhost';
        return frameworkCache;
    }
    try {
        if (win.React || win.ReactDOM) {
            frameworkCache = 'React';
            return frameworkCache;
        }
        if (win.ng || win.getAllAngularRootElements) {
            frameworkCache = 'Angular';
            return frameworkCache;
        }
        if (win.Vue || win.__VUE__) {
            frameworkCache = 'Vue';
            return frameworkCache;
        }
        await waitForDOMReady();
        const reactRoot = doc.querySelector('[data-reactroot], [data-reactid]');
        if (reactRoot) {
            frameworkCache = 'React';
            return frameworkCache;
        }
        const rootContainers = Array.from(doc.querySelectorAll('body > div'));
        const hasReactRoot = rootContainers.some(container => {
            const keys = Object.keys(container);
            return keys.some(key => key.startsWith('__reactContainer'));
        });
        if (hasReactRoot) {
            frameworkCache = 'React';
            return frameworkCache;
        }
        if (doc.querySelector('[ng-version], [ng-app]')) {
            frameworkCache = 'Angular';
            return frameworkCache;
        }
        if (doc.querySelector('[data-v-app]')) {
            frameworkCache = 'Vue';
            return frameworkCache;
        }
        frameworkCache = 'Vanilla';
        return frameworkCache;
    }
    catch (e) {
        frameworkCache = 'error';
        return frameworkCache;
    }
};

export { detectFramework as d, isNestedInIfxComponent as i, trackComponent as t };
//# sourceMappingURL=p-bqYaVeZb.js.map

//# sourceMappingURL=p-bqYaVeZb.js.map