"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModelStandardsValidator = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const ModelStandardsUtility_js_1 = require("./ModelStandardsUtility.js");
/**
 * ModelStandardsValidator Component
 *
 * This component validates model configuration against predefined standards
 * using the ReelCode validation engine.
 */
const ModelStandardsValidator = ({ model, onChange, showWarnings = true }) => {
    const [validationResult, setValidationResult] = (0, react_1.useState)({
        valid: true,
        errors: [],
        warnings: []
    });
    const [isValidating, setIsValidating] = (0, react_1.useState)(false);
    (0, react_1.useEffect)(() => {
        if (!model)
            return;
        let isMounted = true;
        const validateModel = async () => {
            setIsValidating(true);
            try {
                // Use the validateModelStandards function from ModelStandardsUtility
                // which uses the @bluefly/reelcode package
                const result = await (0, ModelStandardsUtility_js_1.validateModelStandards)(model);
                if (isMounted) {
                    setValidationResult(result);
                    onChange?.(result.valid, result);
                }
            }
            catch (error) {
                console.error('Model validation error:', error);
                if (isMounted) {
                    setValidationResult({
                        valid: false,
                        errors: [{
                                rule: 'validation-error',
                                message: `Validation failed: ${error instanceof Error ? error.message : 'Unknown error'}`
                            }],
                        warnings: []
                    });
                    onChange?.(false, validationResult);
                }
            }
            finally {
                if (isMounted) {
                    setIsValidating(false);
                }
            }
        };
        validateModel();
        // Cleanup function to handle component unmounting during async operations
        return () => {
            isMounted = false;
        };
    }, [model, onChange]);
    // Don't render anything if no validation errors or warnings
    if (validationResult.valid && validationResult.warnings.length === 0) {
        return null;
    }
    return ((0, jsx_runtime_1.jsxs)("div", { className: "model-standards-validator mt-4", children: [isValidating && ((0, jsx_runtime_1.jsxs)("div", { className: "text-blue-600 flex items-center mb-2", children: [(0, jsx_runtime_1.jsxs)("svg", { className: "animate-spin -ml-1 mr-2 h-4 w-4", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [(0, jsx_runtime_1.jsx)("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), (0, jsx_runtime_1.jsx)("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }), (0, jsx_runtime_1.jsx)("span", { children: "Validating model against standards..." })] })), !validationResult.valid && validationResult.errors.length > 0 && ((0, jsx_runtime_1.jsxs)("div", { className: "validation-errors bg-red-50 border border-red-200 rounded-md p-3 mb-3", children: [(0, jsx_runtime_1.jsx)("h4", { className: "text-red-700 font-medium mb-2", children: "Standards Validation Errors" }), (0, jsx_runtime_1.jsx)("ul", { className: "list-disc pl-5 text-red-600", children: validationResult.errors.map((error, index) => ((0, jsx_runtime_1.jsxs)("li", { className: "text-sm", children: [(0, jsx_runtime_1.jsxs)("span", { className: "font-medium", children: [error.rule, ":"] }), " ", error.message] }, `error-${index}`))) })] })), showWarnings && validationResult.warnings.length > 0 && ((0, jsx_runtime_1.jsxs)("div", { className: "validation-warnings bg-yellow-50 border border-yellow-200 rounded-md p-3", children: [(0, jsx_runtime_1.jsx)("h4", { className: "text-yellow-700 font-medium mb-2", children: "Standards Validation Warnings" }), (0, jsx_runtime_1.jsx)("ul", { className: "list-disc pl-5 text-yellow-600", children: validationResult.warnings.map((warning, index) => ((0, jsx_runtime_1.jsxs)("li", { className: "text-sm", children: [(0, jsx_runtime_1.jsxs)("span", { className: "font-medium", children: [warning.rule, ":"] }), " ", warning.message] }, `warning-${index}`))) })] }))] }));
};
exports.ModelStandardsValidator = ModelStandardsValidator;
//# sourceMappingURL=ModelStandardsValidator.js.map