// src/global.d.ts

import crypto from 'node:crypto'
import path from 'node:path'

import { clipboard } from 'electron'
import fs from 'fs-extra'
import mime from 'mime'
import { VNode } from 'vue'
import yaml from 'yaml'

declare global {
  export namespace JSX {
    export interface Element extends VNode {}
    export type IntrinsicElements = Record<string, any>
  }
  export interface Window {
    electron: {
      platform: string
      setVisualZoomLevelLimits: (min: number, max: number) => void
      sendRpcSync: (action: string, ...args: any[]) => any
      triggerRPC: <T>(action: string, ...args: any[]) => Promise<T | undefined>
      sendToMain: (channel: string, ...args: any[]) => void
      sendRPC: (action: string, ...args: any[]) => void
      ipcRendererOn: (channel: string, listener: (...args: any[]) => void) => () => void
      ipcRendererCountListeners: (channel: string) => number
      ipcRendererRemoveAllListeners: (channel: string) => void
      clipboard: {
        writeText: typeof clipboard.writeText
      }
      showFilePath: (file: File) => string
      onThemeUpdate: (callback: (css: string) => void) => () => void
    }
    node: {
      path: {
        join: typeof path.join
        dirname: typeof path.dirname
        basename: typeof path.basename
        normalize: typeof path.normalize
        extname: typeof path.extname
        sep: typeof path.sep
        posix: {
          sep: typeof path.posix.sep
        }
      }
      crypto: {
        randomBytes: typeof crypto.randomBytes
        createHash: (algorithm: string, text: string | Buffer) => string
      }
      fs: {
        remove: typeof fs.remove
        readFile: typeof fs.readFile
        readFileSync: typeof fs.readFileSync
        statSync: typeof fs.statSync
      }
      yaml: {
        parse: typeof yaml.parseDocument
      }
      mime: {
        lookup: typeof mime.getType
      }
    }
  }
}
