/**
 * A react hook that returns the Apphouse store that allows
 * access to features such as routing, feedback, shortcuts, etc.
 * @returns The Apphouse store
 */

import React from 'react';
import { IStoreWithBase } from './context.interface';
import { ApphouseContext } from './ApphouseContext';

// eslint-disable-next-line react-refresh/only-export-components
export function useApphouse<T>(): IStoreWithBase<T> {
  const context = React.useContext(ApphouseContext);
  if (context === undefined) {
    throw new Error('useApphouse must be used within a ApphouseProvider');
  }

  return context.store as unknown as IStoreWithBase<T>;
}
