export interface CustomToastOptions {
  message: string
  icon?: string
  duration?: number
  customClass?: string
}

export const useCustomToast = () => {
  const isVisible = useState('customToastVisible', () => false)
  const message = useState('customToastMessage', () => '')
  const icon = useState('customToastIcon', () => '')
  const customClass = useState('customToastClass', () => '')
  const timer = ref<NodeJS.Timeout | null>(null)

  const showCustomToast = (options: CustomToastOptions) => {
    if (timer.value) {
      clearTimeout(timer.value)
    }

    message.value = options.message
    icon.value = options.icon || ''
    customClass.value = options.customClass || ''
    isVisible.value = true

    timer.value = setTimeout(() => {
      isVisible.value = false
    }, options.duration || 3000)
  }

  const hideCustomToast = () => {
    isVisible.value = false
    if (timer.value) {
      clearTimeout(timer.value)
    }
  }

  return {
    isVisible,
    message,
    icon,
    customClass,
    showCustomToast,
    hideCustomToast,
  }
}
