#include "extensions/extensions.h"
#include <stdio.h>

void extensions_init(Profile *profile) {
  // In a full implementation, this would load configuration or state
  g_print("Extensions initialized for profile: %s\n", profile->name);
}

void extensions_attach(WebKitWebView *webview, Profile *profile) {
  WebKitUserContentManager *manager =
      webkit_web_view_get_user_content_manager(webview);

  // Inject DarkReader
  char *darkreader_js = darkreader_get_script();
  if (darkreader_js) {
    WebKitUserScript *script = webkit_user_script_new(
        darkreader_js, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
        WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END, NULL, NULL);
    webkit_user_content_manager_add_script(manager, script);
    webkit_user_script_unref(script);
    g_free(darkreader_js);
  }

  // Inject SponsorBlock
  char *sponsorblock_js = sponsorblock_get_script();
  if (sponsorblock_js) {
    WebKitUserScript *script = webkit_user_script_new(
        sponsorblock_js, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
        WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END, NULL, NULL);
    webkit_user_content_manager_add_script(manager, script);
    webkit_user_script_unref(script);
    g_free(sponsorblock_js);
  }
}
