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

interface ListViewContextType {
  /* FilterSidebar props */
  sidebarOpen?: boolean;
  setSidebarOpen?: (open: boolean) => void;

  /* ListTabsToolbar props */
  currentTabKey?: string;
  setCurrentTabKey?: (key: string) => void;
}

const ListViewContext = createContext<ListViewContextType>({
  sidebarOpen: false,
  setSidebarOpen: () => {},
  currentTabKey: '',
  setCurrentTabKey: () => {}
});

function ListViewProvider(props: { children: React.ReactNode }) {
  const [sidebarOpen, setSidebarOpen] = React.useState(false);
  const [currentTabKey, setCurrentTabKey] = React.useState('');

  return (
    <ListViewContext.Provider value={{ currentTabKey, setCurrentTabKey, sidebarOpen, setSidebarOpen }}>
      {props.children}
    </ListViewContext.Provider>
  );
}

function useListViewContext() {
  return useContext(ListViewContext);
}

export { ListViewProvider, useListViewContext };
