"use strict";
/**
 * Workflow Validation Hook
 * Provides validation functionality for workflow components
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.useWorkflowValidation = void 0;
const react_1 = require("react");
const workflowValidation_1 = require("../utils/workflowValidation");
const useWorkflowValidation = () => {
    // Memoize validation function to prevent unnecessary re-renders
    const validate = (0, react_1.useCallback)((workflow) => {
        return (0, workflowValidation_1.validateWorkflow)(workflow);
    }, []);
    // Memoize summary function
    const getSummary = (0, react_1.useCallback)((result) => {
        return (0, workflowValidation_1.getValidationSummary)(result);
    }, []);
    // Helper to check if validation result has errors
    const hasErrors = (0, react_1.useCallback)((result) => {
        return result.errors.length > 0;
    }, []);
    // Helper to check if validation result has warnings
    const hasWarnings = (0, react_1.useCallback)((result) => {
        return result.warnings.length > 0;
    }, []);
    // Get all errors for a specific node
    const getErrorsByNode = (0, react_1.useCallback)((result, nodeId) => {
        return [
            ...result.errors.filter(error => error.nodeId === nodeId),
            ...result.warnings.filter(error => error.nodeId === nodeId),
        ];
    }, []);
    // Get all errors of a specific type
    const getErrorsByType = (0, react_1.useCallback)((result, errorCode) => {
        const code = workflowValidation_1.ValidationErrorCodes[errorCode];
        return [
            ...result.errors.filter(error => error.code === code),
            ...result.warnings.filter(error => error.code === code),
        ];
    }, []);
    // Memoize the entire result object to prevent unnecessary re-renders
    return (0, react_1.useMemo)(() => ({
        validate,
        getSummary,
        hasErrors,
        hasWarnings,
        getErrorsByNode,
        getErrorsByType,
    }), [
        validate,
        getSummary,
        hasErrors,
        hasWarnings,
        getErrorsByNode,
        getErrorsByType,
    ]);
};
exports.useWorkflowValidation = useWorkflowValidation;
//# sourceMappingURL=useWorkflowValidation.js.map