import { configStore } from "./config";
import { soundPlayer } from "$lib/notifications";

let unsubscribe: (() => void) | null = null;

// Initialize notification settings sync - call this once on app startup
export function initNotificationSync() {
  // Prevent duplicate subscriptions
  if (unsubscribe) return;

  unsubscribe = configStore.config.subscribe(($config) => {
    soundPlayer.setEnabled($config.notifications_enabled);
    soundPlayer.setGlobalVolume($config.notification_volume);
  });
}

// Cleanup function if needed
export function cleanupNotificationSync() {
  if (unsubscribe) {
    unsubscribe();
    unsubscribe = null;
  }
}
