import { notiBar } from '@/shared/lib';
import { useStore } from '@/shared/model/store';
import { useEffect } from 'react';
import { useShallow } from 'zustand/react/shallow';

export const useNotiBar = () => {
  const [notiBarMessage, setNotiBarMessage] = useStore(
    useShallow((state: any) => [
      state.utilEventSlice.notiBarMessage, 
      state.utilEventSlice.setNotiBarMessage
    ])
  );

  useEffect(() => {
    if(notiBarMessage) {
      notiBar(notiBarMessage);
      setNotiBarMessage('');
    }
  }, [notiBarMessage]);
};
