/**
 * commands/variant-pool.mjs — `apt-tools variant-pool [opts]` (C1, Wave 2).
 *
 * Deterministic resolver that returns N typeui-sh style slugs for the
 * `apt:mockup --variants N` flow.  The skill invokes this CLI before
 * spawning N sub-agents in parallel — each sub-agent is handed one
 * `{ slug, name, description, path }` tuple from the returned list and
 * seeds its HTML generation with the referenced SKILL.md.
 *
 * Usage:
 *
 *   apt-tools variant-pool                       # 3 default slugs
 *   apt-tools variant-pool --n 4                 # 4 slugs
 *   apt-tools variant-pool --taste ./taste.yaml  # filter by direction
 *   apt-tools variant-pool --styles-dir <path>   # override typeui-sh path
 *
 * Output envelope (stdout):
 *
 *   {
 *     status: "ok",
 *     command: "variant-pool",
 *     n: 3,
 *     styles: [{ slug, name, description, path }, ...],
 *     warnings: [string, ...]
 *   }
 *
 * `path` is the absolute path to the style's SKILL.md so the orchestrator
 * can pass it straight to the spawned sub-agent's context.
 */
import { existsSync, readFileSync } from 'node:fs';
import { dirname, resolve as resolvePath } from 'node:path';
import { fileURLToPath } from 'node:url';
import { parse as parseYaml } from 'yaml';
import { parseFlags } from '../util/args.mjs';
import { err, ok } from '../util/result.mjs';
import { resolveVariantPool } from '../variant/pool.mjs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// commands/variant-pool.mjs → ../../../../docs/frameworks/…/typeui-sh
// Resolved relative to the shipping package so the CLI works from any cwd.
const DEFAULT_STYLES_DIR = resolvePath(__dirname, '..', '..', '..', '..', '..', 'docs', 'frameworks', 'Design-system', 'examples', 'by-source', 'typeui-sh');
export function cmdVariantPool(extraArgs) {
    const flags = parseFlags(extraArgs ?? []);
    const nFlag = flags.get('n');
    const tasteFlag = flags.get('taste');
    const stylesDirFlag = flags.get('styles-dir');
    const n = typeof nFlag === 'string' || typeof nFlag === 'number' ? nFlag : 3;
    const stylesDir = typeof stylesDirFlag === 'string' && stylesDirFlag.length > 0
        ? resolvePath(stylesDirFlag)
        : DEFAULT_STYLES_DIR;
    if (!existsSync(stylesDir)) {
        return err(`variant-pool: styles directory not found at ${stylesDir}. Pass --styles-dir <path> or re-install the framework.`);
    }
    let taste = null;
    if (typeof tasteFlag === 'string' && tasteFlag.length > 0) {
        const tastePath = resolvePath(tasteFlag);
        if (!existsSync(tastePath)) {
            return err(`variant-pool: taste file not found at ${tastePath}`);
        }
        try {
            const text = readFileSync(tastePath, 'utf8');
            const parsed = parseYaml(text);
            if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
                taste = /** @type {{ direction?: string }} */ (parsed);
            }
        }
        catch (e) {
            const msg = e instanceof Error ? e.message : String(e);
            return err(`variant-pool: failed to parse taste file ${tastePath}: ${msg}`);
        }
    }
    const { slugs, warnings } = resolveVariantPool({ n, taste, stylesDir });
    return ok({
        status: 'ok',
        command: 'variant-pool',
        n: slugs.length,
        styles: slugs,
        warnings,
    });
}
//# sourceMappingURL=variant-pool.mjs.map