import { expect } from "e2e";
import JSZip from "jszip";
import { test, WEB } from "./t3.ts";

async function hiddenColumns() {
  return new JSZip()
    .file("mimetype", "application/vnd.oasis.opendocument.spreadsheet", { compression: "STORE" })
    .file("content.xml", `<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.3"><office:body><office:spreadsheet><table:table table:name="Inventory"><table:table-column table:number-columns-repeated="1025" table:visibility="collapse"/><table:table-column/><table:table-row><table:table-cell table:number-columns-repeated="1025"/><table:table-cell office:value-type="string"><text:p>In stock</text:p></table:table-cell></table:table-row></table:table></office:spreadsheet></office:body></office:document-content>`)
    .generateAsync({ type: "uint8array" });
}

test("ODS preserves AML after 1025 hidden columns", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("ODS repro", { "hidden-columns.ods": await hiddenColumns() });
  const thread = await t3.thread({ project, title: "Inventory preview", messages: ["Start"] });
  await t3.open(thread);
  await screen.getByRole("button", "Toggle right panel").tap();
  await screen.getByRole("button", "Files F").tap();
  await screen.getByRole("treeitem", "hidden-columns.ods").tap();
  await screen.getByText("Sheet 1 of 1", { exact: false }).waitFor({ timeout: 120_000 });
  await screen.getByText("In stock", { exact: true }).waitFor();
  await app.screenshot("hidden-columns-preview");
  await expect(screen.getByRole("columnheader", "AML", { exact: true })).toBeVisible();
  await expect(screen.getByText("Sheet 1 of 1 · 1 row · 1 column", { exact: false })).toBeVisible();
});
