import { isValidTelUrl } from "./is-valid-te-url.js";
import { linkify } from "./linkify/linkify.js";
const normalizeHref = (value) => {
  if (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 && linkify.match(urlValue) && linkify.match(urlValue)?.[0]?.url;
  if (normalizedUrl === null) {
    return void 0;
  }
  return anchor ? `${normalizedUrl}#${anchor}` : normalizedUrl;
};
export {
  normalizeHref
};
//# sourceMappingURL=normalize-href.js.map
