import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";

const source = readFileSync(
  fileURLToPath(new URL("../src/components/StockLotTagSelect.vue", import.meta.url)),
  "utf8"
);

const selectLotStart = source.indexOf("function selectLot(lot)");
const removeLotStart = source.indexOf("function removeLot(lot)");
assert.ok(selectLotStart >= 0 && removeLotStart > selectLotStart, "StockLotTagSelect should define selectLot before removeLot");

const selectLotSource = source.slice(selectLotStart, removeLotStart);

assert.match(
  selectLotSource,
  /dropdownOpen\.value\s*=\s*false/,
  "choosing one stock lot should close the dropdown"
);

assert.doesNotMatch(
  selectLotSource,
  /dropdownOpen\.value\s*=\s*true/,
  "choosing one stock lot should not keep the dropdown open"
);

assert.match(
  source,
  /@focus="dropdownOpen = true"/,
  "clicking back into the search input should open the dropdown again"
);

console.log("stock lot tag select dropdown behavior checks passed");
