import { ADAPTERS, readManifest, tildify } from "@designpaca/core";
import { getVersion } from "../skill.ts";
import { dim, heading, info, ok, padDisplay, table } from "../ui.ts";

export async function runList(): Promise<number> {
  const version = await getVersion();
  const manifest = await readManifest();

  console.log(heading("설치 가능한 대상"));
  for (const a of ADAPTERS) {
    console.log(`  ${padDisplay(a.label, 18)} ${dim(a.hint)}  ${dim(`[${a.scopes.join("|")}]`)}`);
  }

  console.log(heading(`현재 설치 (CLI v${version})`));
  if (manifest.installs.length === 0) {
    console.log(info("없음"));
    return 0;
  }
  for (const rec of manifest.installs) {
    console.log(ok(`${rec.target} (${rec.scope})`));
    console.log(
      table([
        ["위치", tildify(rec.root)],
        ["버전", rec.version],
        ["설치 시각", new Date(rec.installedAt).toLocaleString("ko-KR")],
      ]),
    );
  }
  return 0;
}
