/**
 * Web/Capacitor platform implementation.
 * Uses Web Crypto API, localStorage, and Page Visibility API.
 */
import crypto from './crypto.js';
import session from './session.js';
import settings from './settings.js';
import idle from './idle.js';
import searchStorage from './searchStorage.js';
import SearchDatabase from '@discord-clone/shared/src/utils/SearchDatabase';

const searchDB = new SearchDatabase(searchStorage, crypto);

const webPlatform = {
  crypto,
  session,
  settings,
  idle,
  links: {
    openExternal(url) {
      window.open(url, '_blank', 'noopener,noreferrer');
    },
    async fetchMetadata(url) {
      // On web, metadata fetching would hit CORS. Use a Convex action or proxy instead.
      // Return null to gracefully skip link previews that require server-side fetching.
      return null;
    },
  },
  screenCapture: {
    async getScreenSources() {
      // Web uses getDisplayMedia directly (no source picker like Electron).
      // Return empty array; the web UI should call navigator.mediaDevices.getDisplayMedia() directly.
      return [];
    },
  },
  windowControls: null,
  updates: null,
  searchDB,
  features: {
    hasWindowControls: false,
    hasScreenCapture: true,
    hasNativeUpdates: false,
    hasSearch: true,
  },
};

export default webPlatform;
