'use client'

import { useState } from 'react'
import type { ProcessTask } from './types'

export function SkipModal({
  task,
  onClose,
  onSkip,
}: {
  task: ProcessTask
  onClose: () => void
  onSkip: (reason: string) => Promise<void>
}) {
  const [reason, setReason] = useState('')
  const [saving, setSaving] = useState(false)

  const handleSkip = async () => {
    if (!reason.trim()) return
    setSaving(true)
    try {
      await onSkip(reason)
      onClose()
    } catch {
      setSaving(false)
    }
  }

  return (
    <div className="fixed inset-0 bg-black/40 z-50 flex items-center justify-center p-4" onClick={e => e.target === e.currentTarget && onClose()}>
      <div className="bg-white rounded-2xl shadow-2xl w-full max-w-md">
        <div className="flex items-center justify-between p-6 border-b">
          <h2 className="text-lg font-semibold text-gray-900">Aufgabe ueberspringen</h2>
          <button onClick={onClose} className="text-gray-400 hover:text-gray-600 text-xl">{'\u2715'}</button>
        </div>
        <div className="p-6 space-y-4">
          <p className="text-sm text-gray-600 font-medium">{task.title}</p>
          <div>
            <label className="block text-sm font-medium text-gray-700 mb-1">Begruendung *</label>
            <textarea value={reason} onChange={e => setReason(e.target.value)} rows={3}
              className="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-purple-500"
              placeholder="Warum wird diese Aufgabe uebersprungen?" />
          </div>
        </div>
        <div className="flex justify-end gap-3 p-6 border-t">
          <button onClick={onClose} className="px-4 py-2 text-sm text-gray-600 hover:bg-gray-100 rounded-lg">Abbrechen</button>
          <button onClick={handleSkip} disabled={saving || !reason.trim()}
            className="px-5 py-2 text-sm bg-yellow-500 text-white rounded-lg hover:bg-yellow-600 disabled:opacity-50">
            {saving ? 'Speichern...' : 'Ueberspringen'}
          </button>
        </div>
      </div>
    </div>
  )
}
