// Exercise 2: catch-all segment parsing
//
// Model app/docs/[...slug]/page.tsx. Implement parseDocsPath, which
// takes the `slug` array Next.js would give you (from params) and
// returns:
//   - the joined URL path, e.g. ["a","b","c"] -> "a/b/c"
//   - the "section" (first segment)
//   - the "leaf" (last segment)
// as an object: { path, section, leaf }.
//
// Also handle the optional catch-all case: an empty array means the
// route matched exactly `/docs` with no further segments — in that
// case return { path: "", section: "index", leaf: "index" }.

interface DocsInfo {
  path: string;
  section: string;
  leaf: string;
}

function parseDocsPath(slug: string[]): DocsInfo {
  // TODO: implement per the rules above
  return { path: "", section: "", leaf: "" };
}

// --- self-check: do not modify below this line ---
const cases: [string[], DocsInfo][] = [
  [["a", "b", "c"], { path: "a/b/c", section: "a", leaf: "c" }],
  [["getting-started"], { path: "getting-started", section: "getting-started", leaf: "getting-started" }],
  [[], { path: "", section: "index", leaf: "index" }],
];

let allPass = true;
for (const [input, expected] of cases) {
  const result = parseDocsPath(input);
  const pass = JSON.stringify(result) === JSON.stringify(expected);
  if (!pass) allPass = false;
  console.log(`parseDocsPath(${JSON.stringify(input)}) -> ${JSON.stringify(result)}: ${pass ? "PASS" : "FAIL"}`);
}
console.log(allPass ? "ALL PASS" : "SOME FAILED");
