export const DEFAULT_BREAKPOINTS = {
    mobile: 768,
    tablet: 1024,
    desktop: 1025,
};
export class ScreenWidth {
    static instance;
    breakpoints;
    callbacks;
    resizeTimeout;
    constructor() {
        this.breakpoints = DEFAULT_BREAKPOINTS;
        this.callbacks = new Set();
        this.initializeListeners();
    }
    static getInstance() {
        if (!ScreenWidth.instance) {
            ScreenWidth.instance = new ScreenWidth();
        }
        return ScreenWidth.instance;
    }
    setBreakpoints(breakpoints) {
        this.breakpoints = { ...this.breakpoints, ...breakpoints };
        this.notifyListeners();
    }
    getWidth() {
        if (typeof window === 'undefined')
            return 0;
        return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0;
    }
    isTouch() {
        if (typeof window === 'undefined')
            return false;
        return ('ontouchstart' in window ||
            navigator.maxTouchPoints > 0 ||
            // @ts-ignore - Some browsers might not have msMaxTouchPoints
            navigator.msMaxTouchPoints > 0);
    }
    getScreenSize(width) {
        if (width < this.breakpoints.mobile)
            return 'mobile';
        if (width < this.breakpoints.tablet)
            return 'tablet';
        return 'desktop';
    }
    getScreenInfo() {
        const width = this.getWidth();
        return {
            width,
            size: this.getScreenSize(width),
            isTouch: this.isTouch(),
        };
    }
    initializeListeners() {
        if (typeof window === 'undefined')
            return;
        const handleResize = () => {
            if (this.resizeTimeout) {
                window.clearTimeout(this.resizeTimeout);
            }
            this.resizeTimeout = window.setTimeout(() => {
                this.notifyListeners();
            }, 250);
        };
        window.addEventListener('resize', handleResize);
        window.addEventListener('orientationchange', handleResize);
    }
    notifyListeners() {
        const info = this.getScreenInfo();
        this.callbacks.forEach(callback => callback(info));
    }
    subscribe(callback) {
        this.callbacks.add(callback);
        callback(this.getScreenInfo()); // Initial call
        return () => {
            this.callbacks.delete(callback);
        };
    }
}
//# sourceMappingURL=ScreensizeDetect.js.map
