import React, { useState } from 'react'; import { ShieldCheck, Plus, Play, Trash2, AlertTriangle, CheckCircle2, XCircle, Sliders, Filter, Code2, FileCheck2 } from 'lucide-react'; import { api } from '../api/client'; export default function PolicyRulesLab({ rules, currentWorkspace, onCreateRule, onDeleteRule, onValidate, loading }) { const [showAddModal, setShowAddModal] = useState(false); const [ruleName, setRuleName] = useState(''); const [ruleType, setRuleType] = useState('CONFIDENCE_THRESHOLD'); const [conditionVal, setConditionVal] = useState('0.85'); const [isBlocking, setIsBlocking] = useState(true); const [lintResults, setLintResults] = useState(null); const [validating, setValidating] = useState(false); const handleCreate = async (e) => { e.preventDefault(); if (!ruleName.trim()) return; let condition = {}; if (ruleType === 'CONFIDENCE_THRESHOLD') { condition = { min_confidence: parseFloat(conditionVal) || 0.85 }; } else if (ruleType === 'REGEX_FORMAT') { condition = { pattern: conditionVal }; } else if (ruleType === 'PROVENANCE_MANDATORY') { condition = { require_source: true, enforce_doc_id: true }; } else if (ruleType === 'PHI_PII_GUARD') { condition = { block_ssn_mrn: true, block_patient_names: true }; } else if (ruleType === 'INDEMNITY_CAP_LINT') { condition = { max_cap_multiplier: parseFloat(conditionVal) || 1.0 }; } else if (ruleType === 'JURISDICTION_WHITELIST') { condition = { allowed: conditionVal ? conditionVal.split(',').map(s => s.trim()) : ['DE', 'NY', 'CA', 'UK'] }; } else if (ruleType === 'STATISTICAL_VALIDATION') { condition = { p_value_max: parseFloat(conditionVal) || 0.05, require_confidence_interval: true }; } else if (ruleType === 'TIMELINE_CONSTRAINT') { condition = { max_days: parseInt(conditionVal) || 365 }; } else { condition = { field: conditionVal }; } await onCreateRule(ruleName.trim(), ruleType, condition, isBlocking); setRuleName(''); setShowAddModal(false); }; const runLinter = async () => { if (!currentWorkspace?.id) return; setValidating(true); try { const res = await onValidate(); setLintResults(res); } finally { setValidating(false); } }; return (
Automated quality gates and regulatory guardrails executed before knowledge merges.