import {
  getProjectRoot,
  toKebab
} from "./chunk-DWMLTXKQ.js";
import {
  getConfig,
  getProjectRoot as getProjectRoot2
} from "./chunk-V6OJGLBA.js";

// ../core/dist/wu-paths.js
import * as path from "path";
function resolveRepoRoot(absolutePath, depth) {
  let result = absolutePath;
  for (let i = 0; i < depth; i++) {
    result = path.dirname(result);
  }
  return result;
}
function computePathDepth(relativePath) {
  const normalized = relativePath.replace(/\\/g, "/");
  return normalized.split("/").filter(Boolean).length;
}
function getStateStoreDirFromBacklog(backlogPath) {
  const config = getConfig();
  const depth = computePathDepth(config.directories.backlogPath);
  const repoRoot = resolveRepoRoot(backlogPath, depth);
  return path.join(repoRoot, config.state.stateDir);
}
function createWuPaths(options = {}) {
  const config = getConfig({ projectRoot: options.projectRoot });
  return {
    /**
     * Get path to WU YAML file
     * @param id - WU ID (e.g., 'WU-123')
     * @returns Path to WU YAML file
     */
    WU: (id) => path.join(config.directories.wuDir, `${id}.yaml`),
    /**
     * Get path to WU directory
     * @returns Path to WU directory
     */
    WU_DIR: () => config.directories.wuDir,
    /**
     * Get path to status.md
     * @returns Path to status.md
     */
    STATUS: () => config.directories.statusPath,
    /**
     * Get path to backlog.md
     * @returns Path to backlog.md
     */
    BACKLOG: () => config.directories.backlogPath,
    /**
     * Get path to stamps directory
     * @returns Path to stamps directory
     */
    STAMPS_DIR: () => config.state.stampsDir,
    /**
     * Get path to WU done stamp file
     * @param id - WU ID (e.g., 'WU-123')
     * @returns Path to stamp file
     */
    STAMP: (id) => path.join(config.state.stampsDir, `${id}.done`),
    /**
     * Get path to state directory
     * @returns Path to state directory
     */
    STATE_DIR: () => config.state.stateDir,
    /**
     * Get path to initiatives directory
     * @returns Path to initiatives directory
     */
    INITIATIVES_DIR: () => config.directories.initiativesDir,
    /**
     * Get path to initiative YAML file
     * @param id - Initiative ID (e.g., 'INIT-001')
     * @returns Path to initiative YAML file
     */
    INITIATIVE: (id) => path.join(config.directories.initiativesDir, `${id}.yaml`),
    /**
     * Get path to worktrees directory
     * @returns Path to worktrees directory
     */
    WORKTREES_DIR: () => config.directories.worktrees,
    /**
     * Get path to a specific worktree directory
     * @param lane - Lane name (e.g., 'Framework: Core')
     * @param id - WU ID (e.g., 'WU-123')
     * @returns Path to worktree directory
     */
    WORKTREE: (lane, id) => path.join(config.directories.worktrees, `${toKebab(lane)}-${id.toLowerCase()}`),
    /**
     * Get path to plans directory
     * @returns Path to plans directory (WU-1301)
     */
    PLANS_DIR: () => config.directories.plansDir,
    /**
     * Get path to templates directory
     * @returns Path to templates directory (WU-1310)
     */
    TEMPLATES_DIR: () => config.directories.templatesDir,
    /**
     * Get path to onboarding directory
     * @returns Path to onboarding directory (WU-1310)
     */
    ONBOARDING_DIR: () => config.directories.onboardingDir,
    /**
     * Get path to LumenFlow complete guide
     * @returns Path to complete guide markdown
     */
    COMPLETE_GUIDE_PATH: () => config.directories.completeGuidePath,
    /**
     * Get path to onboarding quick reference commands
     * @returns Path to quick reference markdown
     */
    QUICK_REF_PATH: () => config.directories.quickRefPath,
    /**
     * Get path to onboarding starting prompt
     * @returns Path to starting prompt markdown
     */
    STARTING_PROMPT_PATH: () => config.directories.startingPromptPath,
    /**
     * Get path to WU sizing guide
     * @returns Path to sizing guide markdown
     */
    SIZING_GUIDE_PATH: () => config.directories.sizingGuidePath,
    /**
     * Get path to governance document
     * @returns Path to governance markdown
     */
    GOVERNANCE_PATH: () => config.directories.governancePath
  };
}
var WU_PATHS = createWuPaths();
function defaultWorktreeFrom(doc) {
  if (!doc)
    return null;
  const lane = doc.lane;
  const id = doc.id;
  if (!lane || !id)
    return null;
  const laneStr = String(lane).trim();
  const idStr = String(id).trim();
  if (laneStr === "" || idStr === "")
    return null;
  return createWuPaths().WORKTREE(laneStr, idStr);
}
function resolveFromProjectRoot(relativePath, moduleUrl) {
  let projectRoot;
  try {
    projectRoot = getProjectRoot2();
  } catch {
    projectRoot = moduleUrl ? getProjectRoot(moduleUrl) : process.cwd();
  }
  return path.join(projectRoot, relativePath);
}

export {
  getStateStoreDirFromBacklog,
  createWuPaths,
  WU_PATHS,
  defaultWorktreeFrom,
  resolveFromProjectRoot
};
