#ifndef PluginSearchPathEditor_hpp
#define PluginSearchPathEditor_hpp

#include <JuceHeader.h>
#include <vector>
#include <string>
#include <map>

struct SearchPathSettings {
    SearchPathSettings()
        : useVstDefaultSearchPaths(true),
          useVst3DefaultSearchPaths(true)
    { }
    
    std::unique_ptr<juce::XmlElement> toXml() const;
    void fromXml(juce::XmlElement* elem);
    
    bool useVstDefaultSearchPaths;
    bool useVst3DefaultSearchPaths;
    std::vector<std::string> vstSearchPaths;
    std::vector<std::string> vst3SearchPaths;
};

class SearchPathListModel;

class PluginSearchPathEditor final : public juce::DocumentWindow {
public:
    PluginSearchPathEditor(SearchPathSettings & settings,
                           std::function<void()> closedHandler,
                           std::function<void()> settingsEditedHandler);
    ~PluginSearchPathEditor();
    
    void closeButtonPressed() override;
    void edited();

private:
    std::function<void()> closedHandler;
    std::function<void()> settingsEditedHandler;
    
    SearchPathSettings & settings;
    
    friend class PluginSearchPathEditorContent;
};

class SearchPathEditorWidget final : public juce::Component, public juce::Button::Listener {
public:
    SearchPathEditorWidget(std::vector<std::string> & paths, std::function<void()> edited);
    ~SearchPathEditorWidget();
    
    void resized() override;
    
    void buttonClicked(juce::Button *b) override;
    
private:
    std::vector<std::string> & paths;
    std::function<void()> edited;
    
    std::unique_ptr<SearchPathListModel> listModel;
    juce::ListBox listBox;
    juce::TextButton addButton, removeButton;
    std::unique_ptr<juce::FileChooser> fileChooser;
};

class PluginSearchPathEditorContent final : public juce::Component, public juce::Button::Listener {
public:
    PluginSearchPathEditorContent(PluginSearchPathEditor & editor);
    ~PluginSearchPathEditorContent();
    
    void resized() override;
    void edited();
    void buttonClicked(juce::Button *b) override;
    
private:
    PluginSearchPathEditor & editor;
    
    juce::Label l_vst, l_vst3;
    juce::ToggleButton d_vst, d_vst3;
    SearchPathEditorWidget e_vst, e_vst3;
};

#endif /* PluginSearchPathEditor_hpp */
