export type PromptType = 'info' | 'success' | 'warning' | 'error';

export interface PromptPayload {
  title?: string;
  message: string;
  type?: PromptType;
  duration?: number;
}

type PromptListener = (payload: PromptPayload) => void;

let promptListener: PromptListener | null = null;

export const bindPromptListener = (listener: PromptListener) => {
  promptListener = listener;
  return () => {
    if (promptListener === listener) {
      promptListener = null;
    }
  };
};

export const showPrompt = (payload: PromptPayload) => {
  promptListener?.(payload);
};
