/**
 * Parses progress.md content and extracts any actual metrics found.
 *
 * Looks for:
 * - Metrics table rows with actual values (non-dash)
 * - Status from the header section
 * - Completion timestamps from the status history table
 */
export function parseProgressActuals(content) {
    if (!content || content.trim().length === 0) {
        return null;
    }
    const result = {};
    let hasData = false;
    const devHours = parseMetricRow(content, 'Dev Hours');
    if (devHours !== undefined) {
        result.devHours = devHours;
        hasData = true;
    }
    const reviewHours = parseMetricRow(content, 'Review Hours');
    if (reviewHours !== undefined) {
        result.reviewHours = reviewHours;
        hasData = true;
    }
    const totalCost = parseMetricRow(content, 'Total Cost');
    if (totalCost !== undefined) {
        result.totalCostUsd = totalCost;
        hasData = true;
    }
    const status = parseStatus(content);
    if (status) {
        result.status = status;
        hasData = true;
    }
    const completedAt = parseCompletedAt(content);
    if (completedAt) {
        result.completedAt = completedAt;
        hasData = true;
    }
    return hasData ? result : null;
}
/**
 * Extracts the actual value from a metrics table row.
 * Format: `| Metric Name | estimated | actual |`
 * Returns undefined if the actual column is `-` or missing.
 */
function parseMetricRow(content, metricName) {
    const escapedName = metricName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
    const pattern = new RegExp(`\\|\\s*${escapedName}[^|]*\\|[^|]*\\|\\s*([^|]+)\\|`, 'i');
    const match = pattern.exec(content);
    if (!match?.[1]) {
        return undefined;
    }
    const rawValue = match[1].trim();
    if (rawValue === '-' || rawValue === '') {
        return undefined;
    }
    // Strip $ prefix and parse
    const numeric = parseFloat(rawValue.replace(/^\$/, ''));
    return Number.isNaN(numeric) ? undefined : numeric;
}
/**
 * Extracts the current status from the header section.
 * Format: `**Status:** done`
 */
function parseStatus(content) {
    const match = /\*\*Status:\*\*\s*(\S+)/.exec(content);
    return match?.[1] ?? undefined;
}
/**
 * Extracts the latest completion timestamp from the status history table.
 * Looks for transitions ending in `done` status.
 * Format: `| 2024-01-10T12:00:00Z | implementing → done |`
 */
function parseCompletedAt(content) {
    const pattern = /\|\s*([\dT:.Z-]+)\s*\|[^|]*→\s*done\s*\|/gi;
    let lastMatch = null;
    let current;
    while ((current = pattern.exec(content)) !== null) {
        lastMatch = current;
    }
    return lastMatch?.[1]?.trim() ?? undefined;
}
//# sourceMappingURL=progress-parser.js.map