import assert from "node:assert/strict";

import {
  createMachineFileLoadSummary,
  createMachineFileSaveSummary,
  machineFileLoadLogLines,
  machineFileSaveLogLines,
} from "../../../runtime/ui/ini-panel/machine-file-summary.js";

const saveSummary = createMachineFileSaveSummary({
  ini: "linuxcnc/machines/xyzab-tdr/machine.ini",
  toolTable: "linuxcnc/machines/xyzab-tdr/tool.tbl",
  parameters: "linuxcnc/machines/xyzab-tdr/linuxcnc.var",
}, "linuxcnc/gcode/ui-session.ngc");

assert.deepEqual(saveSummary, {
  iniOpfsPath: "linuxcnc/machines/xyzab-tdr/machine.ini",
  toolTableOpfsPath: "linuxcnc/machines/xyzab-tdr/tool.tbl",
  parameterOpfsPath: "linuxcnc/machines/xyzab-tdr/linuxcnc.var",
  gcodeOpfsPath: "linuxcnc/gcode/ui-session.ngc",
});

assert.deepEqual(
  machineFileSaveLogLines(saveSummary),
  [
    "INI: linuxcnc/machines/xyzab-tdr/machine.ini",
    "Tool table: linuxcnc/machines/xyzab-tdr/tool.tbl",
    "Parameters: linuxcnc/machines/xyzab-tdr/linuxcnc.var",
    "G-code: linuxcnc/gcode/ui-session.ngc",
  ],
);

const loadSummary = createMachineFileLoadSummary({
  ini: "[EMC]\nMACHINE = xyzab-tdr\n",
  toolTable: "T2 P7 Z3.125\n",
  parameters: "5220 1\n",
});

assert.deepEqual(loadSummary, {
  iniBytes: 26,
  toolTableBytes: 13,
  parameterBytes: 7,
});

assert.deepEqual(
  machineFileLoadLogLines(loadSummary),
  [
    "INI bytes: 26",
    "Tool table bytes: 13",
    "Parameter bytes: 7",
  ],
);

assert.deepEqual(
  createMachineFileSaveSummary(null),
  {
    iniOpfsPath: null,
    toolTableOpfsPath: null,
    parameterOpfsPath: null,
    gcodeOpfsPath: null,
  },
);

assert.deepEqual(
  createMachineFileLoadSummary(null),
  {
    iniBytes: 0,
    toolTableBytes: 0,
    parameterBytes: 0,
  },
);

console.log("ini_panel_machine_file_summary_node_smoke=ok");
