export async function selectFile(accept: string): Promise<File | null> {
  return new Promise((resolve) => {
    const input = document.createElement('input');
    input.type = 'file';
    input.accept = accept;
    input.style.display = 'none';

    input.addEventListener('change', () => {
      const file = input.files?.[0] ?? null;
      input.remove();
      resolve(file);
    });
    input.onerror = () => {
      resolve(null);
    };
    input.onabort = () => {
      resolve(null);
    };

    document.body.appendChild(input);
    input.click();
  });
}
