"use strict";
const { contextBridge, ipcRenderer } = require("electron");

const SEND = new Set([
  "pet:ready",
  "pet:hit-rects",
  "pet:drag-start",
  "pet:drag-end",
  "pet:context-menu",
  "pet:tray-icon",
  "pet:state",
  "pet:log",
  "pet:greeted",
]);

const ON = new Set([
  "pet:init",
  "pet:load",
  "pet:scale",
  "pet:settings",
  "pet:event",
  "pet:cursor",
  "pet:cursor-pos",
  "pet:drag-move",
  "pet:drag-ended",
  "pet:ignore-state",
]);

contextBridge.exposeInMainWorld("pet", {
  send(channel, data) {
    if (SEND.has(channel)) ipcRenderer.send(channel, data);
  },
  on(channel, callback) {
    if (!ON.has(channel)) return () => {};
    const listener = (_event, data) => callback(data);
    ipcRenderer.on(channel, listener);
    return () => ipcRenderer.removeListener(channel, listener);
  },
});
