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

const CategoryContext = createContext({
  currentCategory: null,
  setCurrentCategory: () => {}
});

export const useCategory = () => useContext(CategoryContext);

export const withCategory = (Component) => {
  return (props) => {
    const categoryContext = useCategory();
    return <Component {...props} categoryContext={categoryContext} />;
  };
};

export const CategoryContextProvider = ({ children }) => {
  const [currentCategory, setCurrentCategory] = useState(null);

  const setCurrentCategoryWithLog = (category) => {
    console.log('CategoryContext: Setting current category to:', category);
    setCurrentCategory(category);
  };

  return (
    <CategoryContext.Provider value={{ currentCategory, setCurrentCategory: setCurrentCategoryWithLog }}>
      {children}
    </CategoryContext.Provider>
  );
};

