import Button from '@mui/material/Button'
import Stack from '@mui/material/Stack'

type EntityRowActionsProps = {
  onEdit?: () => void
  onDelete?: () => void
  deleteDisabled?: boolean
  confirmDeleteMessage?: string
  editLabel?: string
  deleteLabel?: string
}

export function EntityRowActions({
  onEdit,
  onDelete,
  deleteDisabled = false,
  confirmDeleteMessage,
  editLabel = 'Изменить',
  deleteLabel = 'Удалить',
}: EntityRowActionsProps) {
  return (
    <Stack direction="row" spacing={0.5} sx={{ justifyContent: 'flex-end' }}>
      {onEdit && (
        <Button size="small" onClick={onEdit}>
          {editLabel}
        </Button>
      )}
      {onDelete && (
        <Button
          size="small"
          color="error"
          disabled={deleteDisabled}
          onClick={() => {
            if (confirmDeleteMessage && !confirm(confirmDeleteMessage)) return
            onDelete()
          }}
        >
          {deleteLabel}
        </Button>
      )}
    </Stack>
  )
}
