#pragma once

#include <string>
#include <unordered_map>
#include <vector>

#include "extensions/extension.h"
#include "include/cef_browser.h"

namespace nebula::extensions {

// Loads unpacked Nebula extensions from GetExtensionsDirectory().
// Install by copying an extension folder (with manifest.json) into that path.
class ExtensionManager {
public:
    void Reload();
    bool SetEnabled(const std::string& id, bool enabled);
    const std::vector<Extension>& Extensions() const { return extensions_; }
    std::string ListJson() const;
    void InjectMatching(CefRefPtr<CefBrowser> browser, const std::string& url) const;

private:
    void EnsureInstallReadme() const;
    void LoadDisabledState();
    void SaveDisabledState() const;
    bool LoadExtensionDirectory(const std::filesystem::path& directory);

    std::vector<Extension> extensions_;
    std::unordered_map<std::string, bool> enabled_overrides_;
};

}  // namespace nebula::extensions
