import { createContext, useContext } from 'react';

interface UIStateContextType {
  isMobile: boolean;
}

export const UIStateContext = createContext<UIStateContextType>({
  isMobile: false,
});

export type UiStateProviderProps = React.ReactNode;

export function UIStateProvider({
  children,
  isMobile,
}: {
  children: UiStateProviderProps;
  isMobile: boolean;
}): React.ReactElement {
  return (
    <UIStateContext.Provider value={{ isMobile }}>
      {children}
    </UIStateContext.Provider>
  );
}

export const useUIState = (): UIStateContextType => {
  try {
    const state = useContext(UIStateContext);
    return state;
  } catch (error) {
    throw new Error('UIStateProvider not found');
  }
};