import config from "config";
import { FLAGS, isOn } from "@komi-app/flags-sdk";

const baseUrl = new URL(config.service.url);
const clientUrl = new URL(config.client.url);

export function profileAdminLink(username = "") {
  if (isOn(FLAGS.FEAT_SB_331_COPY_URL_PROMPT)) {
    return `${adminLink(username)}/admin`;
  }
  return `${profileLink(username)}/admin`;
}

export function adminLink(username = "") {
  return `${baseUrl.protocol}//${username}.${baseUrl.host}`;
}

export function profileLink(
  username = "",
  { hideProtocol } = { hideProtocol: false }
) {
  if (isOn(FLAGS.FEAT_SB_331_COPY_URL_PROMPT)) {
    if (hideProtocol) {
      return `${username}.${clientUrl.host}`;
    }
    return `${clientUrl.protocol}//${username}.${clientUrl.host}`;
  }

  if (hideProtocol) {
    return `${username}.${baseUrl.host}`;
  }
  return `${baseUrl.protocol}//${username}.${baseUrl.host}`;
}

export function domainLink() {
  return `${baseUrl.protocol}//${baseUrl.host}`;
}
