export type TOAuthPublicClient = {
  client_id?: string;
  client_name?: string;
  client_uri?: string;
  contacts?: string[];
};

export const getHostFromUrl = (value?: string | null): string | null => {
  if (!value) {
    return null;
  }

  try {
    return new URL(value).host;
  } catch {
    return null;
  }
};

export const isLocalhostHost = (host: string | null): boolean => {
  if (!host) {
    return false;
  }

  if (host.startsWith("[::1]")) {
    return host === "[::1]" || host.startsWith("[::1]:");
  }

  const [hostname] = host.split(":");
  return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1";
};
