import { parseHrefParam, randomCode } from "../utils/utils";

// domain
export function getOrgCode() {
  let domain;
  // const ipFormat = new RegExp(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/);
  const paramCode =
    parseHrefParam(window.location.href, "code") ||
    window.sessionStorage.getItem("paramDomainCode");
  if (paramCode) {
    domain = paramCode;
    window.sessionStorage.setItem("paramDomainCode", domain);
    return domain;
  }

  domain = window.localStorage.getItem("domain_in_url");
  if (domain) return domain;

  const hostname = window.location.hostname;
  domain = hostname.split(".")[0];
  return domain;
}

export const PLATFORM = "WEB";

if (!localStorage.getItem("deviceId")) {
  localStorage.setItem("deviceId", randomCode(32));
}
export const DEVICE_ID = localStorage.getItem("deviceId");
