import { joinURL } from 'ufo';

export function getSpaceNftDisplayUrlFromEndpoint(endpoint: string): string {
  const prefix = endpoint.replace(/\/api\/space\/.+/, '');

  const strArray = endpoint.replace(/\/$/, '').split('/');
  const spaceDid = strArray.at(-4);

  return joinURL(prefix, `/api/space/nft/display?spaceDid=${spaceDid}`);
}

export function getSpaceHomeUrl(endpoint: string): string {
  const baseUrl = endpoint.replace(/\/api\/space\/.+/, '');
  const strArray = endpoint.replace(/\/$/, '').split('/');
  const spaceDid = strArray.at(-4) as string;

  return joinURL(baseUrl, 'space', spaceDid);
}
