var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pisellUrl/utils/urlHelper.ts
var urlHelper_exports = {};
__export(urlHelper_exports, {
  extractDomain: () => extractDomain,
  extractUrlParams: () => extractUrlParams,
  handleUrlClick: () => handleUrlClick,
  isSecureUrl: () => isSecureUrl,
  normalizeUrl: () => normalizeUrl,
  smartNormalizeUrl: () => smartNormalizeUrl
});
module.exports = __toCommonJS(urlHelper_exports);
function normalizeUrl(url, defaultProtocol = "https://") {
  if (!url) return "";
  const trimmedUrl = url.trim();
  if (/^[a-z]+:\/\//i.test(trimmedUrl)) {
    return trimmedUrl;
  }
  return defaultProtocol + trimmedUrl;
}
function smartNormalizeUrl(url) {
  if (!url) return "";
  const trimmedUrl = url.trim();
  if (/^[a-z]+:\/\//i.test(trimmedUrl)) {
    return trimmedUrl;
  }
  if (trimmedUrl.startsWith("localhost") || trimmedUrl.startsWith("127.0.0.1") || trimmedUrl.startsWith("192.168.") || trimmedUrl.startsWith("10.0.") || trimmedUrl.startsWith("172.")) {
    return "http://" + trimmedUrl;
  }
  return "https://" + trimmedUrl;
}
function extractDomain(url) {
  try {
    const normalizedUrl = url.startsWith("http") ? url : "https://" + url;
    const urlObj = new URL(normalizedUrl);
    return urlObj.hostname;
  } catch {
    return url;
  }
}
function handleUrlClick(url, openInNewWindow = true, defaultProtocol = "https://") {
  if (!url) return;
  const normalizedUrl = normalizeUrl(url, defaultProtocol);
  try {
    new URL(normalizedUrl);
  } catch {
    console.warn("Invalid URL:", normalizedUrl);
    return;
  }
  if (openInNewWindow) {
    window.open(normalizedUrl, "_blank", "noopener,noreferrer");
  } else {
    window.location.href = normalizedUrl;
  }
}
function isSecureUrl(url) {
  return url.startsWith("https://");
}
function extractUrlParams(url) {
  try {
    const normalizedUrl = url.startsWith("http") ? url : "https://" + url;
    const urlObj = new URL(normalizedUrl);
    const params = {};
    urlObj.searchParams.forEach((value, key) => {
      params[key] = value;
    });
    return params;
  } catch {
    return {};
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  extractDomain,
  extractUrlParams,
  handleUrlClick,
  isSecureUrl,
  normalizeUrl,
  smartNormalizeUrl
});
