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'
import { DS_ACCENT, DS_BG, DS_SLATE } from '../../lib/ds'

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: DS_ACCENT.warning.main, borderColor: DS_ACCENT.warning.main, '&:hover': { bgcolor: DS_ACCENT.warning.bg, borderColor: DS_ACCENT.warning.dark } }}
        >
          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: DS_ACCENT.success.main, '&:hover': { bgcolor: DS_ACCENT.success.dark } }}
        >
          Genehmigen
        </Button>
      )}
      {canReject && (
        <Button
          size="small"
          variant="outlined"
          disabled={isSubmitting}
          startIcon={<XCircle size={13} />}
          onClick={() => onUpdateStatus('REJECTED')}
          sx={{ textTransform: 'none', fontSize: '0.75rem', color: DS_ACCENT.danger.main, borderColor: DS_ACCENT.danger.main, '&:hover': { bgcolor: DS_ACCENT.danger.bg, borderColor: DS_ACCENT.danger.dark } }}
        >
          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: DS_SLATE[500], borderColor: DS_BG.muted, '&:hover': { bgcolor: DS_SLATE[50] } }}
        >
          JSON
        </Button>
      </Tooltip>
    </Box>
  )
}
