'use client'

import React from 'react'
import { DSRRequest } from '@/lib/sdk/dsr/types'

export function ActionButtons({
  request,
  onVerifyIdentity,
  onExtendDeadline,
  onComplete,
  onReject,
  onAssign,
  onRejectArt11,
}: {
  request: DSRRequest
  onVerifyIdentity: () => void
  onExtendDeadline: () => void
  onComplete: () => void
  onReject: () => void
  onAssign: () => void
  onRejectArt11?: () => void
}) {
  const isTerminal = request.status === 'completed' || request.status === 'rejected' || request.status === 'cancelled'

  if (isTerminal) {
    return (
      <div className="space-y-2">
        <button
          onClick={() => window.open(`/api/sdk/v1/dsr/${request.id}/export-user-data?format=pdf`, '_blank')}
          className="w-full px-4 py-2 text-gray-600 bg-gray-100 hover:bg-gray-200 rounded-lg transition-colors text-sm"
        >
          PDF exportieren
        </button>
        <button
          onClick={() => window.open(`/api/sdk/v1/dsr/${request.id}/export-user-data?format=json`, '_blank')}
          className="w-full px-4 py-2 text-purple-600 bg-purple-50 hover:bg-purple-100 rounded-lg transition-colors text-sm"
        >
          JSON exportieren (Art. 20)
        </button>
        <button
          onClick={() => window.open(`/api/sdk/v1/dsr/${request.id}/export-user-data?format=csv`, '_blank')}
          className="w-full px-4 py-2 text-blue-600 bg-blue-50 hover:bg-blue-100 rounded-lg transition-colors text-sm"
        >
          CSV exportieren
        </button>
      </div>
    )
  }

  return (
    <div className="space-y-2">
      {!request.identityVerification.verified && (
        <>
          <button
            onClick={onVerifyIdentity}
            className="w-full px-4 py-2 bg-yellow-500 text-white hover:bg-yellow-600 rounded-lg transition-colors text-sm font-medium"
          >
            Identitaet verifizieren
          </button>
          {onRejectArt11 && (
            <button
              onClick={onRejectArt11}
              className="w-full px-4 py-2 text-gray-600 bg-gray-50 hover:bg-gray-100 border border-gray-200 rounded-lg transition-colors text-sm"
              title="Person kann anhand der gespeicherten Daten nicht identifiziert werden (Art. 11 DSGVO)"
            >
              Nicht identifizierbar (Art. 11)
            </button>
          )}
        </>
      )}

      <button
        onClick={onAssign}
        className="w-full px-4 py-2 text-purple-600 bg-purple-50 hover:bg-purple-100 rounded-lg transition-colors text-sm"
      >
        {request.assignment.assignedTo ? 'Neu zuweisen' : 'Zuweisen'}
      </button>

      <button
        onClick={onExtendDeadline}
        className="w-full px-4 py-2 text-gray-600 bg-gray-100 hover:bg-gray-200 rounded-lg transition-colors text-sm"
      >
        Frist verlaengern
      </button>

      <div className="border-t border-gray-200 pt-2 mt-2">
        <button
          onClick={onComplete}
          className="w-full px-4 py-2 bg-green-600 text-white hover:bg-green-700 rounded-lg transition-colors text-sm font-medium"
        >
          Abschliessen
        </button>

        <button
          onClick={onReject}
          className="w-full mt-2 px-4 py-2 text-red-600 bg-red-50 hover:bg-red-100 rounded-lg transition-colors text-sm"
        >
          Ablehnen
        </button>
      </div>
    </div>
  )
}
