'use client';

import { createContext, useContext, useState, useCallback } from 'react';

const LoaderContext = createContext({
  loading: false,
  showLoader: () => {},
  hideLoader: () => {},
  setLoading: () => {}
});

export const useLoader = () => useContext(LoaderContext);

export function LoaderProvider({ children }) {
  const [loading, setLoading] = useState(false);

  const showLoader = useCallback(() => {
    setLoading(true);
  }, []);

  const hideLoader = useCallback(() => {
    setLoading(false);
  }, []);

  return (
    <LoaderContext.Provider value={{ loading, setLoading, showLoader, hideLoader }}>
      {children}
    </LoaderContext.Provider>
  );
}