import { writeFile } from "node:fs/promises";
import { expect } from "e2e";
import { IOS, test } from "./t3-mobile.ts";

test("iOS native thread rows expose displayed status and snooze time", IOS, async ({ t3, app, screen, device }) => {
  const project = await t3.project("Accessibility demo");
  await t3.thread({ project, title: "Approval thread", model: "showcase", messages: ["Showcase"] });
  await t3.thread({ project, title: "Finished thread", model: "showcase", messages: ["Showcase"] });
  await t3.open();
  const row = screen.getByRole("other", /Finished thread/).first();
  await row.waitFor({ state: "visible", timeout: 120_000 });
  const evidence: unknown[] = [];
  const capture = async (label: string) => {
    await app.screenshot(label);
    const snapshot = await device.unstable_raw.client.capture.snapshot({});
    evidence.push({ label, nodes: snapshot.nodes.filter((node) => /thread|Snoozed/.test(node.label ?? "")) });
    await writeFile(`${process.env.T3_EVIDENCE_DIR ?? "."}/native-labels-${process.env.T3_SCENARIO_APP_DIR?.includes("ea05ea5e2a") ? "before" : "after"}.json`, JSON.stringify(evidence, null, 2));
  };
  await capture("card-done-native-label");
  await row.longPress();
  await screen.getByText("Snooze", { exact: true }).tap();
  await screen.getByText("In 1 hour", { exact: false }).tap();
  await screen.getByRole("button", /snoozed/i).tap();
  await row.waitFor({ state: "visible" });
  await capture("slim-snooze-native-label");
  await expect(screen.getByRole("other", /Approval thread/).first()).toHaveAccessibleName(/Approval thread, Done/);
  await expect(row).toHaveAccessibleName(/Finished thread, (1h|59m)/);
});
