// Bridge to the legacy global `notify` (simple-notify) injected by the PHP
// template. If it's not present (e.g. running in isolation / tests), fall back
// to console so the call never throws. Shared by common components and the
// features that mount them, so we don't duplicate the bridge per feature.
type Notifier = {
  error: (m: string) => void;
  info: (m: string) => void;
  success: (m: string) => void;
};

const emit = (kind: keyof Notifier, msg: string): void => {
  const legacy = (globalThis as { notify?: Notifier }).notify;
  if (legacy) {
    legacy[kind](msg);
    return;
  }
  if (kind === 'error') console.error(msg);
  else console.log(msg);
};

export const notify = {
  info: (msg: string) => emit('info', msg),
  success: (msg: string) => emit('success', msg),
  error: (msg: string) => emit('error', msg)
};
