/// <reference types="vite/client" />

import type {
  ListDirResult,
  OpenFileResult,
  OpenFolderResult,
  OpenImageResult,
  SaveDialogResult
} from './types/ipc-types'

export interface MyReaderApi {
  openFileDialog: () => Promise<OpenFileResult>
  openFolderDialog: () => Promise<OpenFolderResult>
  openImageDialog: () => Promise<OpenImageResult>
  saveFileDialog: (defaultPath?: string) => Promise<SaveDialogResult>
  readFile: (filePath: string) => Promise<string>
  writeFile: (filePath: string, content: string) => Promise<void>
  listDirectory: (dirPath: string) => Promise<ListDirResult>
  parentDirectory: (dirPath: string) => Promise<string>
  resolveRelativePath: (baseFilePath: string, href: string) => Promise<string>
  openExternal: (url: string) => Promise<void>
  defaultDirectory: () => Promise<string>
  deleteFile: (filePath: string) => Promise<void>
  renamePath: (oldPath: string, newName: string) => Promise<{ newPath: string }>
  allowClose: () => void
  onRequestClose: (handler: () => void) => () => void
  onMenuAction: (handler: (action: string) => void) => () => void
}

declare global {
  interface Window {
    myreader?: MyReaderApi
    showOpenFilePicker?: (options?: OpenFilePickerOptions) => Promise<FileSystemFileHandle[]>
    showSaveFilePicker?: (options?: SaveFilePickerOptions) => Promise<FileSystemFileHandle>
    showDirectoryPicker?: (options?: DirectoryPickerOptions) => Promise<FileSystemDirectoryHandle>
  }
}

export {}
