import { BrowserWindow } from 'electron';
import log from 'electron-log';

/**
 * Creates a function that sends output to a renderer window via IPC
 * and logs it using electron-log
 *
 * @param window - The BrowserWindow to send output to
 * @param channel - The IPC channel name to use
 * @returns A function that sends messages to both the log and the renderer
 */
export function createOutputSender(
  window: BrowserWindow | null,
  channel: string
): (message: string) => void {
  return (message: string) => {
    log.info(message);
    if (window?.webContents) {
      window.webContents.send(channel, message + '\n');
    }
  };
}
