#ifndef INPUT_HPP
#define INPUT_HPP

#include "config.h"

#include <string>
#include <map>
#include <vector>

#include <cc++/thread.h>

// structure used for input keys
class Input
{
public:
  std::string mode, key, command, name;
  bool multiple;

  std::string to_string() const;
  // create from string
  Input(std::string& s);

  Input();
};

// used as superclass of input devices
class Input_device : public ost::Thread
{
 public:

  // helper function
  Input get_input();

  // for searching
  void enable_all_input() { accept_all = true; }
  void disable_all_input() { accept_all = false; }

  virtual void suspend() = 0;
  virtual void wake_up() = 0;

  virtual ~Input_device() {};
  Input_device();

 protected:
  bool accept_all;

  Input input;

  ost::Event input_ready;
  ost::Event input_done_;

 private:

  virtual void run() = 0;
};

typedef std::map<std::string, Input> input_map;
typedef std::vector<Input> input_list;

class Input_master
{
private:
  static Input_master* instance;

protected:
  Input_master();

public:

  std::string find_shortcut(const std::string& command);
  input_list cur_list();

  // input maps
  input_map startmenu;
  input_list startmenu_l;

  input_map standard;
  input_list standard_l;

  input_map movies;
  input_list movies_l;

#ifdef use_graphical_movie
  input_map movie_imdb;
  input_list movie_imdb_l;
#endif

  // audio
  input_map audio_add;
  input_list audio_add_l;
  input_map playlist;
  input_list playlist_l;
  input_map playlist_load;
  input_list playlist_load_l;

  input_map pictures;
  input_list pictures_l;

  input_map epg;
  input_list epg_l;

  input_map search;
  input_list search_l;

  input_map *cur_map;
  input_map *last_map;
  Input_device *device;

  void parse_keys();

  static Input_master* get_instance();
  ~Input_master();
};
#endif
