import React from 'react';
import ReactDOM from 'react-dom';
import { createStore } from 'redux';
import Dropdown from './Dropdown';

function reducer(state = { open: false }, action) {
  switch (action.type) {
    case 'TOGGLE_DROPDOWN':
      return {
        ...state,
        open: !state.open
      };
    default:
      return state;
  }
}

const store = createStore(reducer);

const App = (props) => (
  <div>
    <Dropdown
      label="Click me"
      open={store.getState().open}
      onClick={() => {
        store.dispatch({ action: 'TOGGLE_DROPDOWN' });
      }}
    />
  </div>
);

function render() {
  ReactDOM.render(<App />, document.getElementById('root'));
}

store.subscribe(render);
render();