import { invoke } from '@tauri-apps/api/core';

export interface AppInfo {
  name: string;
  version: string;
  tauri_version: string;
}

export interface FileContent {
  path: string;
  content: string;
  size: number;
}

export interface DirectoryEntry {
  name: string;
  path: string;
  is_dir: boolean;
  size: number;
}

export async function getAppInfo(): Promise<AppInfo> {
  return invoke('get_app_info');
}

export async function openDirectoryDialog(): Promise<string | null> {
  return invoke('open_directory_dialog');
}

export async function readLocalFile(path: string): Promise<FileContent> {
  return invoke('read_local_file', { path });
}

export async function listDirectory(path: string): Promise<DirectoryEntry[]> {
  return invoke('list_directory', { path });
}

export function isTauri(): boolean {
  return typeof window !== 'undefined' && '__TAURI__' in window;
}
