"use strict";
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);
var normalize_href_exports = {};
__export(normalize_href_exports, {
  normalizeHref: () => normalizeHref
});
module.exports = __toCommonJS(normalize_href_exports);
var import_is_valid_te_url = require("./is-valid-te-url.js");
var import_linkify = require("./linkify/linkify.js");
const normalizeHref = (value) => {
  if ((0, import_is_valid_te_url.isValidTelUrl)(value)) {
    return value;
  }
  if (value.startsWith("mailto:")) {
    const [email, ...queryParts] = value.substring(7).split("?");
    const queryString = queryParts.join("?");
    const sanitizedQuery = queryString ? `?${new URLSearchParams(queryString).toString()}` : "";
    return `mailto:${email}${sanitizedQuery}`;
  }
  const [urlValue, anchor] = value.split("#");
  const normalizedUrl = urlValue && import_linkify.linkify.match(urlValue) && import_linkify.linkify.match(urlValue)?.[0]?.url;
  if (normalizedUrl === null) {
    return void 0;
  }
  return anchor ? `${normalizedUrl}#${anchor}` : normalizedUrl;
};
//# sourceMappingURL=normalize-href.js.map
