import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { readFileSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";

const __dirname = dirname(fileURLToPath(import.meta.url));

function readComponent(name) {
  return readFileSync(join(__dirname, name), "utf8");
}

const mainCss = readFileSync(resolve(__dirname, "../../styles/main.css"), "utf8");

describe("document form foundation", () => {
  it("provides generic system-wide paper form components", () => {
    [
      "DocumentFormShell.vue",
      "DocumentSection.vue",
      "DocumentActionBar.vue",
      "DocumentField.vue",
      "DocumentSelectorPanel.vue",
      "DocumentInlineSummary.vue",
      "DocumentSettlePanel.vue"
    ].forEach((name) => {
      const source = readComponent(name);
      assert.match(source, /document-/);
    });
  });

  it("keeps warehouse wrappers as compatibility adapters over generic document components", () => {
    assert.match(readComponent("WarehouseDocumentFormShell.vue"), /import DocumentFormShell/);
    assert.match(readComponent("WarehouseDocumentSection.vue"), /import DocumentSection/);
    assert.match(readComponent("WarehouseDocumentActionBar.vue"), /import DocumentActionBar/);
  });

  it("exposes a generic action host without removing the existing warehouse host", () => {
    const paper = readComponent("DocumentPaper.vue");
    assert.match(paper, /data-document-action-host/);
    assert.match(paper, /data-warehouse-document-action-host/);
  });

  it("defines generic document paper controls and keeps warehouse aliases compatible", () => {
    assert.match(mainCss, /\.document-form-shell/);
    assert.match(mainCss, /\.document-section-grid/);
    assert.match(mainCss, /\.document-paper-field/);
    assert.match(mainCss, /\.document-selector-panel/);
    assert.match(mainCss, /\.document-inline-summary/);
    assert.match(mainCss, /\.document-settle-panel/);
    assert.match(mainCss, /\.warehouse-paper-control-grid/);
  });
});
