// @bun
import {
  resolveCommandContext
} from "./chunk-2jcqy5j6.js";
import {
  createCliLogger
} from "./chunk-t993tmz7.js";
import {
  auth,
  workspaceCache
} from "./chunk-7krp2mgz.js";

// src/utils/workspace-display.ts
function normalizeOptions(input) {
  return typeof input === "string" ? { projectPath: input } : input ?? {};
}
async function resolveDisplayContext(options) {
  if (options.context) {
    return {
      credentials: options.context.credentials,
      workspaceId: options.context.workspaceId ?? options.context.credentials.workspaceId,
      workspaceName: options.context.credentials.workspaceName,
      profileName: options.context.selectedProfile.name
    };
  }
  if (options.projectPath) {
    const context = await resolveCommandContext({
      cwd: options.projectPath,
      target: "dev",
      require: ["project", "credentials", "workspace"],
      createClient: false
    });
    return {
      credentials: context.credentials,
      workspaceId: context.workspaceId,
      workspaceName: context.credentials.workspaceName,
      profileName: context.selectedProfile.name
    };
  }
  const credentials = await auth.getActiveCredentials();
  const profile = await auth.getCurrentProfileDetails();
  return {
    credentials,
    workspaceId: credentials.workspaceId,
    workspaceName: credentials.workspaceName,
    profileName: profile?.name || "default"
  };
}
async function displayWorkspaceInfo(input) {
  const logger = createCliLogger();
  try {
    const options = normalizeOptions(input);
    const { credentials, workspaceId, profileName } = await resolveDisplayContext(options);
    let workspaceName = credentials.workspaceName;
    if (workspaceId && (!workspaceName || options.projectPath || options.context)) {
      const fetchedName = await workspaceCache.getWorkspaceName(workspaceId, credentials);
      if (fetchedName) {
        workspaceName = fetchedName;
      }
    }
    logger.newline();
    logger.info("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501", "cyan");
    logger.info(`Workspace: ${workspaceName || workspaceId || "Unknown"}`, "cyan");
    logger.info(`Workspace ID: ${workspaceId || "Unknown"}`, "gray");
    logger.info(`Profile: ${profileName}`, "gray");
    logger.info("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501", "cyan");
    logger.newline();
  } catch {
    logger.warn('\u26A0\uFE0F  Unable to display workspace info. Please run "adk login" first.');
    logger.newline();
  }
}

export { displayWorkspaceInfo };
