'use client'

export type ApprovalModalMode = 'approve-internal' | 'approve-client' | 'reject'

interface ApprovalModalProps {
  mode: ApprovalModalMode
  approvalComment: string
  onCommentChange: (comment: string) => void
  onCancel: () => void
  onConfirm: () => void
  saving: boolean
}

const TITLES: Record<ApprovalModalMode, string> = {
  'approve-internal': 'DSB-Freigabe → an Mandant weiterleiten',
  'approve-client': 'Mandanten-Freigabe erteilen',
  reject: 'Version ablehnen',
}

const BUTTON_LABELS: Record<ApprovalModalMode, string> = {
  'approve-internal': 'DSB-Freigabe erteilen',
  'approve-client': 'Mandanten-Freigabe erteilen',
  reject: 'Ablehnen',
}

const PLACEHOLDERS: Record<ApprovalModalMode, string> = {
  'approve-internal':
    'Kommentar (optional) — Hinweise für den Mandanten...',
  'approve-client':
    'Kommentar (optional) — z.B. Freigabe durch Geschäftsführung...',
  reject: 'Ablehnungsgrund...',
}

export default function ApprovalModal({
  mode,
  approvalComment,
  onCommentChange,
  onCancel,
  onConfirm,
  saving,
}: ApprovalModalProps) {
  const isReject = mode === 'reject'
  return (
    <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50">
      <div className="bg-white rounded-xl shadow-xl p-6 w-full max-w-md">
        <h3 className="text-lg font-semibold text-slate-900 mb-4">{TITLES[mode]}</h3>
        <textarea
          value={approvalComment}
          onChange={(e) => onCommentChange(e.target.value)}
          placeholder={PLACEHOLDERS[mode]}
          className="w-full px-3 py-2 border border-slate-300 rounded-lg min-h-[100px] mb-4"
          required={isReject}
        />
        <div className="flex justify-end gap-3">
          <button
            onClick={onCancel}
            className="px-4 py-2 text-slate-600 hover:text-slate-900"
          >
            Abbrechen
          </button>
          <button
            onClick={onConfirm}
            disabled={saving || (isReject && !approvalComment)}
            className={`px-4 py-2 text-white rounded-lg disabled:opacity-50 ${
              isReject ? 'bg-red-600 hover:bg-red-700' : 'bg-green-600 hover:bg-green-700'
            }`}
          >
            {saving ? 'Wird verarbeitet...' : BUTTON_LABELS[mode]}
          </button>
        </div>
      </div>
    </div>
  )
}
