import { Box, Button, Tooltip } from '@mui/material'
import { CheckCircle, XCircle, Send, Copy } from 'lucide-react'
import type { AIOutput } from '../../domain/aiOutput'
import type { ReviewStatus } from '../../domain/enums'

interface Props {
  output: AIOutput
  onUpdateStatus: (status: ReviewStatus) => void
  onCopyJson: () => void
  isSubmitting?: boolean
}

export function AIReviewActionToolbar({ output, onUpdateStatus, onCopyJson, isSubmitting }: Props) {
  const { reviewStatus } = output

  const canSendToReview = reviewStatus === 'UNREVIEWED' || reviewStatus === 'FLAGGED'
  const canApprove = reviewStatus === 'IN_REVIEW' || reviewStatus === 'UNREVIEWED'
  const canReject = reviewStatus !== 'REJECTED'

  return (
    <Box sx={{ display: 'flex', gap: 0.75, flexWrap: 'wrap' }}>
      {canSendToReview && (
        <Button
          size="small"
          variant="outlined"
          disabled={isSubmitting}
          startIcon={<Send size={13} />}
          onClick={() => onUpdateStatus('IN_REVIEW')}
          sx={{ textTransform: 'none', fontSize: '0.75rem', color: '#d97706', borderColor: '#d97706', '&:hover': { bgcolor: '#fffbeb', borderColor: '#b45309' } }}
        >
          Zur Prüfung
        </Button>
      )}
      {canApprove && (
        <Button
          size="small"
          variant="contained"
          disabled={isSubmitting}
          startIcon={<CheckCircle size={13} />}
          onClick={() => onUpdateStatus('APPROVED')}
          sx={{ textTransform: 'none', fontSize: '0.75rem', bgcolor: '#1a7a4a', '&:hover': { bgcolor: '#155f3a' } }}
        >
          Genehmigen
        </Button>
      )}
      {canReject && (
        <Button
          size="small"
          variant="outlined"
          disabled={isSubmitting}
          startIcon={<XCircle size={13} />}
          onClick={() => onUpdateStatus('REJECTED')}
          sx={{ textTransform: 'none', fontSize: '0.75rem', color: '#c0392b', borderColor: '#c0392b', '&:hover': { bgcolor: '#fef2f2', borderColor: '#a93226' } }}
        >
          Ablehnen
        </Button>
      )}
      <Tooltip title="Output-JSON kopieren">
        <Button
          size="small"
          variant="outlined"
          onClick={onCopyJson}
          startIcon={<Copy size={13} />}
          sx={{ textTransform: 'none', fontSize: '0.75rem', color: '#64748b', borderColor: '#e8e7e4', '&:hover': { bgcolor: '#f8fafc' } }}
        >
          JSON
        </Button>
      </Tooltip>
    </Box>
  )
}
