import { inject, provide, ref } from "vue";
import { getUid } from "@veno-ui/utils";
const MessageKey = Symbol.for("veno-ui:message");
const NotificationKey = Symbol.for("veno-ui:notification");
const message = createMessage();
const notification = createMessage();
function createMessage() {
  const items = ref([]);
  function open(props) {
    return function(text, rest) {
      const id = `ve-message-${getUid()}`;
      const item = {
        id,
        text,
        modelValue: true,
        variant: "contained",
        elevation: 15,
        duration: 3e3,
        close: () => close(id),
        ...props,
        ...rest
      };
      items.value.push(item);
      if (item.duration > 0) {
        return new Promise((resolve) => {
          setTimeout(() => {
            item.close();
            resolve(item);
          }, item.duration);
        });
      }
      return item.close;
    };
  }
  function close(id) {
    const item = items.value.find((v) => v.id === id);
    if (item) {
      item.modelValue = false;
    }
  }
  function remove(id) {
    items.value.splice(items.value.findIndex((v) => v.id === id), 1);
  }
  return {
    items,
    open,
    info: open({ type: "info" }),
    success: open({ type: "success" }),
    warning: open({ type: "warning" }),
    error: open({ type: "error" }),
    loading: open({ loading: true }),
    close,
    remove
  };
}
function provideMessage() {
  const message2 = createMessage();
  provide(MessageKey, message2);
  return message2;
}
function useMessage() {
  const message2 = inject(MessageKey);
  if (!message2)
    throw new Error("[VenoUi] Could not find message instance");
  return message2;
}
function provideNotification() {
  const notification2 = createMessage();
  provide(NotificationKey, notification2);
  return notification2;
}
function useNotification() {
  const notification2 = inject(NotificationKey);
  if (!notification2)
    throw new Error("[VenoUi] Could not find notification instance");
  return notification2;
}
export {
  MessageKey,
  NotificationKey,
  createMessage,
  message,
  notification,
  provideMessage,
  provideNotification,
  useMessage,
  useNotification
};
//# sourceMappingURL=index.mjs.map
