'use client'
import { useState } from 'react'
import Toast from "../components/shared/Toast"
import { NotificationContext } from './notification-context'

export function NotificationProvider({ children }: { children: React.ReactNode }) {
  const [message, setMessage] = useState('')
  const [type, setType] = useState<'success' | 'error'>('success')
  const [isVisible, setIsVisible] = useState(false)

  const showNotification = (message: string, type: 'success' | 'error') => {
    setMessage(message)
    setType(type)
    setIsVisible(true)
  }

  const hideNotification = () => {
    setIsVisible(false)
  }

  return (
    <NotificationContext.Provider value={{ showNotification, hideNotification }}>
      {children}
      <Toast 
        message={message} 
        type={type} 
        isVisible={isVisible} 
        onClose={hideNotification} 
      />
    </NotificationContext.Provider>
  )
}
