const DEFAULT_SITE_URL = "https://video.haus";

export const SITE_NAME = "video.haus";
export const SITE_TITLE = "video.haus | Creator Video Tools";
export const SITE_DESCRIPTION =
  "Fast video tools for creators. Extract frames, audio, thumbnails, and formats in one workspace.";

function toAbsoluteUrl(value: string) {
  const trimmedValue = value.trim();
  if (!trimmedValue) {
    return DEFAULT_SITE_URL;
  }

  if (trimmedValue.startsWith("http://") || trimmedValue.startsWith("https://")) {
    return trimmedValue;
  }

  return `https://${trimmedValue}`;
}

export function getSiteUrl() {
  const configuredUrl = process.env.NEXT_PUBLIC_SITE_URL || process.env.SITE_URL || DEFAULT_SITE_URL;

  try {
    return new URL(toAbsoluteUrl(configuredUrl));
  } catch {
    return new URL(DEFAULT_SITE_URL);
  }
}

export function getAbsoluteUrl(pathname = "/") {
  return new URL(pathname, getSiteUrl()).toString();
}

