export function openWindowWithPost(url: string, data: Record<string, any>, target = "_blank") {
  const form = document.createElement("form");
  form.target = target;
  form.method = "POST";
  form.action = url;
  form.style.display = "none";

  const createInput = (name: string, value: any) => {
    const input = document.createElement("input");
    input.type = "hidden";
    input.name = name;
    input.value = JSON.stringify(value);
    return input;
  };

  Object.entries(data).forEach(([key, value]) => {
    form.appendChild(createInput(key, value));
  });

  document.body.appendChild(form);
  form.submit();
  document.body.removeChild(form);
}
