'use client'

import { Button } from '@/components/ui/button'
import { useLanguage } from '@/lib/i18n'
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
} from '@/components/ui/dialog'
import { useNotebooks } from '@/context/notebooks-context'

interface DeleteNotebookDialogProps {
  notebook: any
  open: boolean
  onOpenChange: (open: boolean) => void
}

export function DeleteNotebookDialog({ notebook, open, onOpenChange }: DeleteNotebookDialogProps) {
  const { deleteNotebook } = useNotebooks()
  const { t } = useLanguage()

  const handleDelete = async () => {
    try {
      await deleteNotebook(notebook.id)
      onOpenChange(false)
    } catch (error) {
      // Error already handled in UI
    }
  }

  return (
    <Dialog open={open} onOpenChange={onOpenChange}>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>{t('notebook.delete')}</DialogTitle>
          <DialogDescription>
            {t('notebook.deleteWarning', { notebookName: notebook?.name })}
          </DialogDescription>
        </DialogHeader>
        <DialogFooter>
          <Button variant="outline" onClick={() => onOpenChange(false)}>
            {t('general.cancel')}
          </Button>
          <Button variant="destructive" onClick={handleDelete}>
            {t('notebook.deleteConfirm')}
          </Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}
