/**
 * @license
 * Copyright 2025 Vybestack LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { useCallback } from 'react';
/**
 * @plan PLAN-20260129-TODOPERSIST.P03
 * @fix FIX-1336-EMPTY-CLEAR
 * Determine whether todos should be cleared based on their state.
 * Returns true only if all todos are completed (user finished their work).
 * Returns false if the list is empty (nothing to clear) or has incomplete todos.
 */
export function shouldClearTodos(todos) {
    if (todos.length === 0) {
        return false;
    }
    return todos.every((t) => t.status === 'completed');
}
export class TodoPausePreserver {
    preserveNextSubmission = false;
    /**
     * @plan PLAN-20260129-TODOPERSIST.P01
     * Modified to accept todos parameter for conditional clearing logic.
     */
    handleSubmit(onClear, todos) {
        if (this.preserveNextSubmission) {
            this.preserveNextSubmission = false;
            return;
        }
        if (shouldClearTodos(todos)) {
            onClear();
        }
    }
    registerTodoPause() {
        this.preserveNextSubmission = true;
    }
}
export const useTodoPausePreserver = ({ controller, updateTodos, handleFinalSubmit, todos, }) => {
    const handleUserInputSubmit = useCallback((submittedValue) => {
        controller.handleSubmit(() => {
            updateTodos([]);
        }, todos);
        handleFinalSubmit(submittedValue);
    }, [controller, updateTodos, handleFinalSubmit, todos]);
    return {
        handleUserInputSubmit,
    };
};
//# sourceMappingURL=useTodoPausePreserver.js.map