import React from 'react';
import { Provider } from 'react-redux';
import SearchResultsConfigurationContext from './search-results-configuration-context';
import { SearchResultsConfiguration } from './types';
import SearchResultsContainer from './components/search-results-container/search-results-container';
import { createSearchResultsStore } from './store/search-results-store';

interface SearchResultsProps {
  configuration: SearchResultsConfiguration;
  onBookingStarted?: () => void;
}

const SearchResults: React.FC<SearchResultsProps> = ({ configuration, onBookingStarted }) => {
  const store = React.useMemo(() => createSearchResultsStore(), []);

  return (
    <Provider store={store}>
      <SearchResultsConfigurationContext.Provider value={configuration}>
        <SearchResultsContainer onBookingStarted={onBookingStarted} />
      </SearchResultsConfigurationContext.Provider>
    </Provider>
  );
};

export default SearchResults;
