const CSS_LINK_ID = "sb-theme";

export const changeCSS = (cssUrl: string) => {
  // Find CSS <link> element with id = "sb-theme"
  const theme: HTMLElement | null = document.getElementById(CSS_LINK_ID);

  if (theme) {
    theme.setAttribute("href", cssUrl);
  } else {
    // Append a new link to document and set href
    const link = document.createElement("link");
    link.setAttribute("type", "text/css");
    link.setAttribute("rel", "stylesheet");
    link.setAttribute("href", cssUrl);
    link.setAttribute("id", CSS_LINK_ID);
    document.head.appendChild(link);
  }
};
