import { MalwareThreatFile } from '../../../utils/malwareReport';

export { canVerifySafe, resolveVerifySafeState, shouldShowVerifySafeAction } from './VerifySafeAction';

interface VerifySafeDialogProps {
    threat: MalwareThreatFile;
    open: boolean;
    onCancel: () => void;
    onConfirm: () => void;
    isSubmitting: boolean;
}

export function VerifySafeDialog({ threat, open, onCancel, onConfirm, isSubmitting }: VerifySafeDialogProps) {
    if (!open) {
        return null;
    }

    return (
        <div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/80 p-4">
            <div className="w-full max-w-lg rounded-2xl border border-slate-700 bg-slate-900 p-6 shadow-2xl">
                <h4 className="text-lg font-bold text-white">Mark File as Safe / Trusted</h4>
                <p className="mt-3 text-sm text-slate-300 leading-relaxed">
                    This will trust ONLY this exact file fingerprint.
                </p>
                <p className="mt-2 text-sm text-slate-400 leading-relaxed">
                    Future plugin updates, hash changes, path changes, or file modifications will automatically invalidate this trust.
                    Future malware injections will NOT remain trusted.
                </p>

                <div className="mt-4 rounded-xl border border-slate-800 bg-slate-950/60 p-3 text-xs text-slate-400 space-y-1">
                    <div><span className="text-slate-500">Path:</span> <span className="font-mono text-slate-300">{threat.path}</span></div>
                    {threat.plugin_slug && (
                        <div><span className="text-slate-500">Plugin:</span> {threat.plugin_name || threat.plugin_slug} v{threat.plugin_version}</div>
                    )}
                    {threat.sha256 && (
                        <div className="truncate"><span className="text-slate-500">SHA-256:</span> <span className="font-mono">{threat.sha256}</span></div>
                    )}
                </div>

                <div className="mt-6 flex justify-end gap-3">
                    <button
                        type="button"
                        onClick={onCancel}
                        disabled={isSubmitting}
                        className="rounded-xl border border-slate-700 px-4 py-2 text-sm text-slate-300 hover:bg-slate-800/60"
                    >
                        Cancel
                    </button>
                    <button
                        type="button"
                        onClick={onConfirm}
                        disabled={isSubmitting}
                        className="rounded-xl bg-emerald-600 px-4 py-2 text-sm font-semibold text-white hover:bg-emerald-500 disabled:opacity-60"
                    >
                        {isSubmitting ? 'Saving…' : 'Mark as Safe'}
                    </button>
                </div>
            </div>
        </div>
    );
}
