import {
  ɵɵdefineInjectable
} from "./chunk-XLNHGGTT.js";

// src/app/services/check-device.service.ts
var OS;
(function(OS2) {
  OS2[OS2["unknown"] = 0] = "unknown";
  OS2[OS2["Windows"] = 1] = "Windows";
  OS2[OS2["WindowsPhone"] = 2] = "WindowsPhone";
  OS2[OS2["macOS"] = 3] = "macOS";
  OS2[OS2["ios"] = 4] = "ios";
  OS2[OS2["Android"] = 5] = "Android";
  OS2[OS2["Linux"] = 6] = "Linux";
})(OS || (OS = {}));
var Browser;
(function(Browser2) {
  Browser2[Browser2["unknown"] = 0] = "unknown";
  Browser2[Browser2["SamsungBrowser"] = 1] = "SamsungBrowser";
  Browser2[Browser2["Chromium"] = 2] = "Chromium";
  Browser2[Browser2["Firefox"] = 3] = "Firefox";
  Browser2[Browser2["Safari"] = 4] = "Safari";
  Browser2[Browser2["edge"] = 5] = "edge";
  Browser2[Browser2["webView"] = 6] = "webView";
})(Browser || (Browser = {}));
var iOSDevice;
(function(iOSDevice2) {
  iOSDevice2[iOSDevice2["iPhone"] = 1] = "iPhone";
  iOSDevice2[iOSDevice2["iPad"] = 2] = "iPad";
  iOSDevice2[iOSDevice2["iPod"] = 3] = "iPod";
})(iOSDevice || (iOSDevice = {}));
var _CheckDeviceService = class _CheckDeviceService {
  constructor() {
    this.userAgent = navigator.userAgent;
  }
  createDeviceSignature() {
    return this.checkBrowserUserAgent().replace(/\./g, "_");
  }
  checkBrowserUserAgentData() {
    const userAgentData = navigator.userAgentData;
    if (!userAgentData) {
      return "";
    }
    const { brands, platform } = userAgentData;
    const os = +OS[platform];
    const browser = brands.find(({ brand }) => !!Browser[brand]);
    if (!browser || !os || isNaN(os)) {
      return "";
    }
    return `${this.getOSSignature(os)}br${Browser[browser.brand]}v${browser.version}`;
  }
  checkBrowserUserAgent() {
    const osSignature = this.getOSSignature(this.getOS());
    const browserSignature = this.getBrowserSignature();
    return `${osSignature}${browserSignature}`;
  }
  getOSSignature(os) {
    if (os === OS.Windows) {
      return `os${os}v${this.getWindowsVersion()}`;
    }
    if (os === OS.WindowsPhone) {
      return `os${os}v${this.getWindowsPhoneVersion()}v${this.getAndroidVersion()}`;
    }
    if (os === OS.macOS) {
      return `os${os}v${this.getFullMacOSVersion()}`;
    }
    if (os === OS.Android) {
      return `os${os}v${this.getAndroidVersion()}`;
    }
    if (os === OS.ios) {
      return `os${os}v${this.getFulliOSVersion()}`;
    }
    if (os === OS.Linux) {
      return `os${os}vnone`;
    }
    return "";
  }
  getOS() {
    if (this.isWindowsOS()) {
      return OS.Windows;
    }
    if (this.isWindowsPhone()) {
      return OS.WindowsPhone;
    }
    if (this.isMacOS()) {
      return OS.macOS;
    }
    if (this.isAndroid()) {
      return OS.Android;
    }
    if (this.isiOS()) {
      return OS.ios;
    }
    if (this.isLinuxOS()) {
      return OS.Linux;
    }
    return OS.unknown;
  }
  getBrowserSignature() {
    if (this.isSamsungBrowser()) {
      return `br${Browser.SamsungBrowser}v${this.getSamsungBrowserVersion()}`;
    }
    if (this.isChrome()) {
      return `br${Browser.Chromium}v${this.getFullChromeVersion()}`;
    }
    if (this.isFirefox()) {
      return `br${Browser.Firefox}v${this.getFirefoxVersion()}`;
    }
    if (this.isSafari()) {
      return `br${Browser.Safari}v${this.getSafariVersion()}`;
    }
    if (this.isEdgeiOS()) {
      return `${Browser.edge}`;
    }
    if (this.isWebView()) {
      return `${Browser.webView}`;
    }
    return `${Browser.unknown}`;
  }
  isWindowsOS() {
    return /Windows\sNT/i.test(this.userAgent);
  }
  isWindowsPhone() {
    return /Windows\sPhone/i.test(this.userAgent);
  }
  isMacOS() {
    return /Macintosh/i.test(this.userAgent);
  }
  isAndroid() {
    return /Android/i.test(this.userAgent);
  }
  isiOS() {
    return /iPhone|iPad|iPod/i.test(this.userAgent);
  }
  isLinuxOS() {
    return /Linux/i.test(this.userAgent);
  }
  isChrome() {
    return /CriOS|Chrome|Chromium/i.test(this.userAgent);
  }
  isSamsungBrowser() {
    return /SamsungBrowser/i.test(this.userAgent);
  }
  isFirefox() {
    return /Firefox|FxiOS/i.test(this.userAgent);
  }
  isEdgeiOS() {
    return /EdgiOS/i.test(this.userAgent);
  }
  getWindowsVersion() {
    const match = this.userAgent.match(/Windows\sNT\s([0-9]+(\.[0-9]+)?)/i);
    if (!match || !match[1]) {
      return "";
    }
    return match[1];
  }
  getWindowsPhoneVersion() {
    const match = this.userAgent.match(/Windows\sPhone\s([0-9]+)/i);
    if (!match || !match[1]) {
      return "";
    }
    return match[1];
  }
  getAndroidVersion() {
    const match = this.userAgent.match(/Android\s([0-9\.]*)/i);
    if (!match || !match[1]) {
      return "";
    }
    return match[1];
  }
  getAndroidVersionAsNumber() {
    const match = this.userAgent.match(/Android\s([0-9\.]*)/i);
    return match ? parseInt(match[1], 10) : 0;
  }
  getFullMacOSVersion() {
    const match = this.userAgent.match(/OS\sX\s([0-9]+(_[0-9]+)?(_[0-9]+)?)/i);
    if (!match || !match[1]) {
      return "";
    }
    return match[1];
  }
  getFulliOSVersion() {
    const match = this.userAgent.match(/OS\s([0-9]+(_[0-9]+)?(_[0-9]+)?)/i);
    if (!match || !match[1]) {
      return "";
    }
    return match[1];
  }
  getiOSVersionAsNumber() {
    const userAgent = this.userAgent.match(/OS\s([0-9]+_?[0-9])/i);
    return userAgent ? parseInt(userAgent[1].replace("_", "."), 10) : 0;
  }
  getFirefoxVersion() {
    const match = this.userAgent.match(/(Firefox|FxiOS)\/([0-9]+)/i);
    if (!match || !match[2]) {
      return "";
    }
    return match[2];
  }
  getSamsungBrowserVersion() {
    const match = this.userAgent.match(/SamsungBrowser\/([0-9]+.[0-9]+)/i);
    if (!match || !match[1]) {
      return "";
    }
    return match[1];
  }
  getFullChromeVersion() {
    const match = this.userAgent.match(/(CriOS|Chrome|Chromium)\/([0-9]+(.[0-9]+)?(.[0-9]+)?(.[0-9]+)?)/i);
    if (!match || !match[2]) {
      return "";
    }
    return match[2];
  }
  getSafariVersion() {
    const match = this.userAgent.match(/Version\/([0-9]+.[0-9].?[0-9]?)/i);
    if (!match || !match[1]) {
      return "";
    }
    return match[1];
  }
  getSafariVersionAsNumber() {
    const userAgent = this.userAgent.match(/Version\/([0-9]+.[0-9])/i);
    return userAgent ? parseInt(userAgent[1], 10) : 0;
  }
  isMobile() {
    return this.isAndroid() || this.isiOS();
  }
  isSafari() {
    return /^((?!chrome|android).)*safari/i.test(this.userAgent);
  }
  isWebView() {
    return !!this.userAgent.match(/(WebView|(iPhone|iPod|iPad)(?!.*Safari)|Android.*(;\s+wv|Version\/\d.\d\s+Chrome\/\d+(\.0){3})|Linux; U; Android)/gi);
  }
};
_CheckDeviceService.\u0275fac = function CheckDeviceService_Factory(t) {
  return new (t || _CheckDeviceService)();
};
_CheckDeviceService.\u0275prov = /* @__PURE__ */ \u0275\u0275defineInjectable({ token: _CheckDeviceService, factory: _CheckDeviceService.\u0275fac, providedIn: "root" });
var CheckDeviceService = _CheckDeviceService;

export {
  CheckDeviceService
};
