import assert from "node:assert/strict";
import test from "node:test";

import { isWorkbenchNavigationContext, shouldReflectWorkbenchSessionUrl } from "../src/router/workbench-navigation.ts";

test("workbench navigation context recognizes workbench routes only while the component is active", () => {
  assert.equal(isWorkbenchNavigationContext({ componentActive: true, routeSection: "workbench", routeName: "CodeWorkbenchSession", routePath: "/workbench/sessions/ses_1" }), true);
  assert.equal(isWorkbenchNavigationContext({ componentActive: true, routeName: "CodeWorkbench", routePath: "/workspace" }), true);
  assert.equal(isWorkbenchNavigationContext({ componentActive: true, routeSection: "user", routeName: "Dashboard", routePath: "/dashboard" }), false);
  assert.equal(isWorkbenchNavigationContext({ componentActive: false, routeSection: "workbench", routeName: "CodeWorkbenchSession", routePath: "/workbench/sessions/ses_1" }), false);
});

test("workbench URL reflection never rewrites a user navigation outside Workbench", () => {
  assert.equal(shouldReflectWorkbenchSessionUrl({ componentActive: true, routeSection: "user", routeName: "Dashboard", routePath: "/dashboard", routeSessionId: null, sessionId: "ses_async" }), false);
  assert.equal(shouldReflectWorkbenchSessionUrl({ componentActive: false, routeSection: "workbench", routeName: "CodeWorkbench", routePath: "/workbench", routeSessionId: null, sessionId: "ses_async" }), false);
});

test("workbench URL reflection still updates empty Workbench routes and respects route hydration", () => {
  assert.equal(shouldReflectWorkbenchSessionUrl({ componentActive: true, routeSection: "workbench", routeName: "CodeWorkbench", routePath: "/workbench", routeSessionId: null, sessionId: "ses_selected" }), true);
  assert.equal(shouldReflectWorkbenchSessionUrl({ componentActive: true, routeSection: "workbench", routeName: "CodeWorkbenchSession", routePath: "/workbench/sessions/ses_selected", routeSessionId: "ses_selected", sessionId: "ses_selected" }), false);
  assert.equal(shouldReflectWorkbenchSessionUrl({ componentActive: true, routeSection: "workbench", routeName: "CodeWorkbenchSession", routePath: "/workbench/sessions/ses_route", routeSessionId: "ses_route", sessionId: "ses_store", applyingRouteSession: true }), false);
});
