export interface BrowserFeatures {
  secureContext: boolean;
  workers: boolean;
  indexedDb: boolean;
  opfs: boolean;
  fileSystemAccess: boolean;
  crossOriginIsolated: boolean;
  sharedArrayBuffer: boolean;
}

export function detectBrowserFeatures(): BrowserFeatures {
  const scope = globalThis as typeof globalThis & {
    showSaveFilePicker?: unknown;
  };
  return {
    secureContext: globalThis.isSecureContext === true,
    workers: typeof Worker !== 'undefined',
    indexedDb: typeof indexedDB !== 'undefined',
    opfs: typeof navigator.storage?.getDirectory === 'function',
    fileSystemAccess: typeof scope.showSaveFilePicker === 'function',
    crossOriginIsolated: globalThis.crossOriginIsolated === true,
    sharedArrayBuffer: typeof SharedArrayBuffer !== 'undefined',
  };
}
