import { confirmStore } from "./store";


const createId = () =>{
  return typeof crypto !== "undefined" && crypto.randomUUID
    ? crypto.randomUUID()
    : `${Date.now()}_${Math.random()}`;
}
// let id = createId();

export function confirmDialog(options: {
  title: string;
  content?: string;
  noOk?: boolean;
  noCancel?: boolean;
}) {
  return new Promise<boolean>((resolve) => {
    const state = confirmStore.getSnapshot();

    confirmStore.setState({
      queue: [
        ...state.queue,
        {
          id: createId(),
          ...options,
          resolve,
        },
      ],
    });
  });
}