/** Module window: identity, language and window life cycle. */
import { call, subscribeStrict } from "../transport";
import type { ModuleManifest } from "../types";

export const info = () => call<ModuleManifest>("module_get_info", "plugin:getInfo");
export const close = () => call<{ ok: true }>("module_close", "plugin:close");
export const minimize = () => call<{ ok: true }>("module_window_minimize", "plugin:window:minimize");

/** Where the module runs: embedded in the main window or in its own window. */
export const host = Object.freeze({
  state: () => call<{ embedded: boolean }>("module_host_state", "plugin:host:state"),
  detach: () => call<{ embedded: boolean }>("module_host_detach", "plugin:host:detach"),
  attach: () => call<{ embedded: boolean }>("module_host_attach", "plugin:host:attach")
});

export const ui = Object.freeze({
  getLanguage: () => call<string>("module_ui_get_language", "plugin:ui:getLanguage"),
  onLanguageChanged: (callback: (language: string) => void) => subscribeStrict("module:ui:languageChanged", callback, "Language")
});
