"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeviceUtil = void 0;
class DeviceUtil {
    static parseUserAgent(userAgent) {
        const ua = userAgent.toLowerCase();
        return {
            browser: this.detectBrowser(ua),
            version: this.detectBrowserVersion(ua),
            os: this.detectOS(ua),
            device: this.detectDevice(ua),
            isMobile: this.isMobile(ua),
            isTablet: this.isTablet(ua),
            isDesktop: this.isDesktop(ua),
        };
    }
    static detectBrowser(ua) {
        if (ua.includes('edg/'))
            return 'Edge';
        if (ua.includes('chrome/'))
            return 'Chrome';
        if (ua.includes('firefox/'))
            return 'Firefox';
        if (ua.includes('safari/') && !ua.includes('chrome'))
            return 'Safari';
        if (ua.includes('opera') || ua.includes('opr/'))
            return 'Opera';
        return 'Unknown';
    }
    static detectBrowserVersion(ua) {
        const match = ua.match(/(chrome|firefox|safari|edg|opr)\/(\d+)/);
        return match ? match[2] : 'Unknown';
    }
    static detectOS(ua) {
        if (ua.includes('windows nt'))
            return 'Windows';
        if (ua.includes('mac os x'))
            return 'macOS';
        if (ua.includes('linux'))
            return 'Linux';
        if (ua.includes('android'))
            return 'Android';
        if (ua.includes('iphone') || ua.includes('ipad'))
            return 'iOS';
        return 'Unknown';
    }
    static detectDevice(ua) {
        if (ua.includes('iphone'))
            return 'iPhone';
        if (ua.includes('ipad'))
            return 'iPad';
        if (ua.includes('android'))
            return 'Android';
        if (ua.includes('windows phone'))
            return 'Windows Phone';
        if (ua.includes('macintosh'))
            return 'Mac';
        if (ua.includes('windows'))
            return 'Windows PC';
        if (ua.includes('linux'))
            return 'Linux PC';
        return 'Unknown';
    }
    static isMobile(ua) {
        return /mobile|android|iphone|ipod|blackberry|windows phone/i.test(ua);
    }
    static isTablet(ua) {
        return /ipad|android(?!.*mobile)|tablet/i.test(ua);
    }
    static isDesktop(ua) {
        return !this.isMobile(ua) && !this.isTablet(ua);
    }
    static getDeviceName(userAgent) {
        const parsed = this.parseUserAgent(userAgent);
        if (parsed.isMobile) {
            return `${parsed.device} (${parsed.browser})`;
        }
        if (parsed.isTablet) {
            return `${parsed.device} Tablet (${parsed.browser})`;
        }
        return `${parsed.os} (${parsed.browser})`;
    }
}
exports.DeviceUtil = DeviceUtil;
//# sourceMappingURL=device.util.js.map