/**
 * Playback mode — controlled globally by the admin via a toggle in the
 * admin panel ("External Player ON/OFF"). The frontend syncs the current
 * value from /api/public/playback-mode into localStorage on boot (see
 * usePlaybackMode hook) so VideoPlayer can read it synchronously.
 *
 *  - "internal" (default):  in-app ExoPlayer (PlayerActivity). Web fallback
 *                            is HLS.js / mpegts.js inside an HTML5 <video>.
 *  - "external":            hand off to VLC / MX Player / Brouken via intent.
 *
 * The default of "internal" is the safest fallback: if the admin-config
 * fetch fails or localStorage is empty, videos still play inside the app
 * (no dependency on a third-party player being installed).
 */

export type PlaybackMode = "internal" | "external";

const STORAGE_KEY = "nadiplay_playback_mode";

export const getPlaybackMode = (): PlaybackMode => {
  try {
    const v = localStorage.getItem(STORAGE_KEY);
    return v === "external" ? "external" : "internal";
  } catch {
    return "internal";
  }
};

export const setPlaybackMode = (mode: PlaybackMode): void => {
  try {
    localStorage.setItem(STORAGE_KEY, mode);
  } catch {
    /* ignore */
  }
};
