/**
 * Workbook scope — controls which open Excel workbooks the agent can see.
 *
 * Scope modes: "unset" (default, resolves to all), "all", "none", or
 * "selected" (an explicit subset of workbook names). The scope is
 * resolved against the list of currently-open workbooks so stale
 * selections fall back to "all" rather than silently hiding everything.
 */
export const SCOPE_UNSET = 'unset';
export const SCOPE_ALL = 'all';
export const SCOPE_NONE = 'none';
export const SCOPE_SELECTED = 'selected';
/** Resolve a WorkbookScope against the currently-open workbooks, collapsing "unset" to "all" and dropping stale selections. */
export function resolveWorkbookScope(scope, openWorkbooks) {
    if (scope.mode === SCOPE_NONE) {
        return { mode: SCOPE_NONE };
    }
    if (scope.mode === SCOPE_ALL || scope.mode === SCOPE_UNSET) {
        return { mode: SCOPE_ALL };
    }
    const openSet = new Set(openWorkbooks);
    const selected = scope.workbooks.filter((name) => openSet.has(name));
    if (selected.length === 0) {
        return { mode: SCOPE_ALL };
    }
    return { mode: SCOPE_SELECTED, workbooks: selected };
}
/** Return the workbook names visible under the given scope. */
export function getScopedWorkbookNames(scope, openWorkbooks) {
    const resolved = resolveWorkbookScope(scope, openWorkbooks);
    if (resolved.mode === SCOPE_NONE)
        return [];
    return resolved.mode === SCOPE_ALL ? [...openWorkbooks] : [...resolved.workbooks];
}
/** Resolve scope and return both the active mode and the matching workbook names. */
export function getWorkbookScopeDetails(scope, openWorkbooks) {
    const resolved = resolveWorkbookScope(scope, openWorkbooks);
    return {
        scopeMode: resolved.mode,
        workbooks: getScopedWorkbookNames(scope, openWorkbooks)
    };
}
/** Format a human-readable annotation for display in the UI footer. */
export function formatWorkbookScopeAnnotation(details) {
    if (details.scopeMode === SCOPE_NONE) {
        return '📝 No workbook';
    }
    if (details.workbooks.length === 0) {
        return null;
    }
    if (details.scopeMode === SCOPE_ALL) {
        return '📚 All open workbooks';
    }
    if (details.workbooks.length === 1) {
        return `📗 ${details.workbooks[0]}`;
    }
    return `📚 ${details.workbooks.join(', ')}`;
}
//# sourceMappingURL=workbook-scope.js.map