import { readonly, ref } from 'vue';

const notifications = ref([]);
function useNotification() {
  const add = (notification) => {
    const id = `notification-${Date.now()}-${Math.random().toString(36).slice(2)}`;
    const newNotification = {
      id,
      duration: 5e3,
      ...notification
    };
    notifications.value.push(newNotification);
    if (newNotification.duration && newNotification.duration > 0) {
      setTimeout(() => {
        remove(id);
      }, newNotification.duration);
    }
  };
  const remove = (id) => {
    const index = notifications.value.findIndex((n) => n.id === id);
    if (index !== -1) {
      notifications.value.splice(index, 1);
    }
  };
  const success = (message, duration) => {
    add({ type: "success", message, ...duration !== void 0 && { duration } });
  };
  const error = (message, duration) => {
    add({ type: "error", message, duration: duration ?? 8e3 });
  };
  const warning = (message, duration) => {
    add({ type: "warning", message, ...duration !== void 0 && { duration } });
  };
  const info = (message, duration) => {
    add({ type: "info", message, ...duration !== void 0 && { duration } });
  };
  return {
    notifications: readonly(notifications),
    add,
    remove,
    success,
    error,
    warning,
    info
  };
}

export { useNotification as u };
//# sourceMappingURL=useNotification-BqDqaGnC.mjs.map
