import React from 'react';

import useStore from '../store';
import useActions from '../actions';

import NavbarComponent from '../components/Navbar';
import Search from '../components/Search';
import Annotations from '../components/Annotations';
import Thumbnails from './Thumbnails';

const Navbar = () => {
  const [{ navbarState }, dispatch] = useStore();
  const { switchNavbar } = useActions(dispatch);

  const onClick = (state: string) => {
    if (state === navbarState) {
      switchNavbar('');  
    } else {
      switchNavbar(state);
    }
  };

  const transferProps = (role: string) => ({
    isActive: navbarState === role,
    close: () => { onClick(''); },
  });

  return (
    <NavbarComponent
      onClick={onClick}
      navbarState={navbarState}
    >
      <Search {...transferProps('search')} />
      <Annotations {...transferProps('annotations')} />
      <Thumbnails />
    </NavbarComponent>
  );
};

export default Navbar;
