'use client'

import { useState } from 'react'
import type { VerificationItem } from './verification-types'

export function CompleteModal({
  item, onSubmit, onClose,
}: {
  item: VerificationItem
  onSubmit: (id: string, result: string, passed: boolean) => void
  onClose: () => void
}) {
  const [result, setResult] = useState('')
  const [passed, setPassed] = useState(true)

  return (
    <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4">
      <div className="bg-white dark:bg-gray-800 rounded-xl w-full max-w-lg p-6">
        <h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-4">
          Verifikation abschliessen: {item.title}
        </h3>
        <div className="space-y-4">
          <div>
            <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Ergebnis</label>
            <textarea
              value={result} onChange={(e) => setResult(e.target.value)}
              rows={3} placeholder="Beschreiben Sie das Ergebnis der Verifikation..."
              className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-transparent dark:bg-gray-700 dark:border-gray-600 dark:text-white"
            />
          </div>
          <div>
            <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Bewertung</label>
            <div className="flex gap-3">
              <button
                onClick={() => setPassed(true)}
                className={`flex-1 py-2 rounded-lg border text-sm font-medium transition-colors ${passed ? 'border-green-400 bg-green-50 text-green-700' : 'border-gray-200 text-gray-500 hover:bg-gray-50'}`}
              >
                Bestanden
              </button>
              <button
                onClick={() => setPassed(false)}
                className={`flex-1 py-2 rounded-lg border text-sm font-medium transition-colors ${!passed ? 'border-red-400 bg-red-50 text-red-700' : 'border-gray-200 text-gray-500 hover:bg-gray-50'}`}
              >
                Nicht bestanden
              </button>
            </div>
          </div>
        </div>
        <div className="mt-6 flex items-center gap-3">
          <button
            onClick={() => onSubmit(item.id, result, passed)} disabled={!result}
            className={`px-6 py-2 rounded-lg font-medium transition-colors ${result ? 'bg-purple-600 text-white hover:bg-purple-700' : 'bg-gray-200 text-gray-400 cursor-not-allowed'}`}
          >
            Abschliessen
          </button>
          <button onClick={onClose} className="px-4 py-2 text-gray-600 hover:bg-gray-100 rounded-lg transition-colors">Abbrechen</button>
        </div>
      </div>
    </div>
  )
}
