export function hasWwwDomainPrefix(value: string) {
  const hostname = value
    .trim()
    .toLowerCase()
    .replace(/^https?:\/\//, "");

  return hostname.startsWith("www.");
}

export function getWwwDomainSuggestion(value: string) {
  const hostname = value
    .trim()
    .toLowerCase()
    .replace(/^https?:\/\//, "")
    .replace(/[/?#].*$/, "")
    .replace(/:\d+$/, "");
  const domain = hostname
    .replace(/^www\./, "")
    .replace(/[^a-z0-9.-]/g, "")
    .replace(/^\.+|\.+$/g, "");

  return domain || "officialsite.kr";
}

export function getWwwDomainInputMessage(value: string) {
  return `www를 제외한 도메인으로 입력해주세요. 예: ${getWwwDomainSuggestion(value)}`;
}
