import Domurl from 'domurl';
import { PAGE_INFO } from 'editorCore/FormComponents/ImageList1/data';

export function getUrlParamByKey(key: string) {
  var url_string = window.location.href.replace(/\/#/g, "");
  var url = new URL(url_string);
  return url.searchParams.get(key) || '';
}

export function getPathParamByKey(key: string, path: string) {
  var u = new Domurl(path);
  return (u.query as any)[key] || '';
}

export function isPathWithParam(url: string) {
  return /[?&]([A-Za-z]+)=([^&]+)/.test(url);
}

export function changeParamByPath(path: string, key: string, value: string) {
  if (path.includes("plugin-private")) {
    return PAGE_INFO.liveRoom.template + value
  }
  var u = new Domurl(path);
  (u.query as any)[key] = value;

  return `${u.path}?${(u.query as any).toString()}`;
}

