import React, { useState } from 'react'; import { CornerUpRight, X, Loader, AlertCircle } from 'lucide-react'; const API_BASE = process.env.REACT_APP_API_BASE || 'http://localhost:3001/api'; const WORKFLOW_OPTIONS = [ { key: 'FP', label: 'FP', col: '#F59E0B', rgb: '245,158,11' }, { key: 'Archer', label: 'Archer', col: '#0EA5E9', rgb: '14,165,233' }, { key: 'CARD', label: 'CARD', col: '#10B981', rgb: '16,185,129' }, { key: 'GRANITE', label: 'GRANITE', col: '#A1887F', rgb: '161,136,127' }, ]; export default function RedirectModal({ item, onClose, onRedirect }) { const [workflowType, setWorkflowType] = useState('FP'); const [vendor, setVendor] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const needsVendor = workflowType === 'FP' || workflowType === 'Archer'; const canSubmit = !loading && (!needsVendor || vendor.trim().length > 0); const handleSubmit = async () => { if (!canSubmit) return; setLoading(true); setError(''); try { const body = { workflow_type: workflowType }; if (needsVendor) body.vendor = vendor.trim(); const res = await fetch(`${API_BASE}/ivanti/todo-queue/${item.id}/redirect`, { method: 'POST', credentials: 'include', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), }); const data = await res.json(); if (!res.ok) { setError(data.error || 'Redirect failed.'); setLoading(false); return; } onRedirect(data); onClose(); } catch (err) { setError(err.message || 'Network error.'); setLoading(false); } }; return (