export const getLocalFile = async (accept?: string): Promise<File> => (await open(accept, false))[0];
export const getLocalFiles = (accept?: string): Promise<File[]> => open(accept, true)

const open = (accept?: string, multiple?: boolean): Promise<File[]> => new Promise((resolve, reject) => {
  const input = document.createElement("input");
  input.type = "file";
  if (accept) input.accept = accept;
  if (multiple) input.multiple = multiple;
  input.addEventListener("change", () => {
    resolve(Array.from(input.files ?? []));
  });
  input.addEventListener("error", reject);
  input.click();
});