import { reactive } from "vue";

const notice = reactive({ text: "", type: "info" });
let noticeTimer = null;

function showNotice(text, type = "info", duration = 3200) {
  notice.text = text;
  notice.type = type;
  if (noticeTimer) clearTimeout(noticeTimer);
  noticeTimer = setTimeout(() => {
    notice.text = "";
    noticeTimer = null;
  }, duration);
}

export function useNotice() {
  return { notice, showNotice };
}
