import { Command } from 'commander';
import { callDaemon } from '../client/http-client.js';

export function registerInspectCommands(program: Command) {
  program
    .command('snapshot')
    .description('获取页面 ARIA 树（YAML 格式，含 [ref=eN] 供 click/fill 使用）')
    .requiredOption('--session <name>')
    .option('--raw')
    .action(async (opts) => {
      const r = await callDaemon('/admin/browser-daemon/snapshot', { sessionName: opts.session });
      if (opts.raw) {
        console.log(JSON.stringify(r));
      } else {
        console.log(`Page: ${r.url ?? '(unknown)'}`);
        if (r.text && r.text.trim()) {
          console.log(r.text);
        } else {
          console.log('(empty page — 页面可能还在加载或已重定向到登录页，用 screenshot 确认)');
        }
      }
    });
}
