import { test, expect } from "@app/tests/helpers/stub-test-base";

test.describe("4. PDF Tool Pages - Common Patterns", () => {
  test.describe("4.1 Tool Page - File Upload Required Before Processing", () => {
    test("should require file upload before processing on merge tool", async ({
      page,
    }) => {
      // Step 1: Navigate to the merge tool page
      await page.goto("/merge");
      await page.waitForLoadState("domcontentloaded");

      // Step 2: Verify the primary action button is disabled
      const actionButton = page
        .getByRole("button", { name: /merge|gabungkan/i })
        .first();
      await expect(actionButton).toBeVisible({ timeout: 10000 });
      await expect(actionButton).toBeDisabled();

      // Step 3: Verify the file upload area is displayed
      // (input[type="file"] is excluded — it is hidden in the FileSidebar)
      await expect(
        page.locator('[class*="upload"], [class*="dropzone"]').first(),
      ).toBeVisible();

      // Step 4: Verify that clicking the disabled action button does nothing
      await actionButton.click({ force: true });
      await expect(page).toHaveURL(/\/merge/);
    });
  });

  test.describe("4.2 Tool Page - Navigation Back to Home", () => {
    test("should navigate between tool pages and home via breadcrumbs and history", async ({
      page,
    }) => {
      // Step 1: Navigate to /compress
      await page.goto("/compress");
      await page.waitForLoadState("domcontentloaded");

      // Step 2: Click the "Back to all tools" button in ToolPanel to go back to /.
      // In the redesigned UI this replaces the old "Tools" sidebar link.
      const homeLink = page
        .getByRole("button", { name: /Back to all tools/i })
        .first();
      await homeLink.click();

      // Step 3: Verify navigation back to the home dashboard
      await expect(page).toHaveURL("/");

      // Step 4: Use browser back button
      await page.goBack();

      // Step 5: Verify return to the tool page
      await expect(page).toHaveURL(/\/compress/);
    });
  });
});
