import { ref } from 'vue';

const visible = ref(false);
const message = ref('');

let hideTimer = 0;

export function useAppToast() {
  function showToast(text: string, duration = 2200) {
    message.value = text;
    visible.value = true;
    window.clearTimeout(hideTimer);
    hideTimer = window.setTimeout(() => {
      visible.value = false;
    }, duration);
  }

  return {
    visible,
    message,
    showToast,
  };
}
