// `window.WAYSILL`: what the PHP side prints before every Waysill script (waysill_script_data() and the extra values
// of waysill_enqueue_entry()).
import type { Settings } from "@income-factory/core";

export interface WaysillData {
  /** The bundled, unmodified axe-core release file. */
  axeUrl: string;
  settings: Settings;
  canSeeResults: boolean;
  checkOnSave: boolean;
  /** Settings → Waysill for administrators, else empty. */
  settingsUrl: string;
  postId?: number;
  previewUrl?: string;
  highlightNonce?: string;
  /** Only on a preview opened by Show in preview, after the server checked the nonce and the user's rights. */
  highlight?: { selector: string; number: number; title: string };
}

declare global {
  interface Window {
    WAYSILL?: WaysillData;
  }
}

export function waysillData(): WaysillData {
  const data = window.WAYSILL;
  if (!data) throw new Error("window.WAYSILL is missing.");
  return data;
}
