'use client'

import React from 'react'
import type { Editor } from '@tiptap/react'
import { Toggle } from '@/components/ui/toggle'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
import { Undo, Redo } from 'lucide-react'

interface HistoryMenuProps {
  editor: Editor | null
  disabled?: boolean
  executeCommand: (command: () => void) => void
}

export function HistoryMenu({ editor, disabled, executeCommand }: HistoryMenuProps) {
  if (!editor) return null
  return (
    <>
      <Tooltip>
        <TooltipTrigger asChild>
          <Toggle size="sm" pressed={false} onPressedChange={() => executeCommand(() => editor.chain().focus().undo().run())} disabled={!editor.can().undo() || disabled}>
            <Undo className="h-4 w-4" />
          </Toggle>
        </TooltipTrigger>
        <TooltipContent>
          <p>실행 취소 (Ctrl+Z)</p>
        </TooltipContent>
      </Tooltip>
      <Tooltip>
        <TooltipTrigger asChild>
          <Toggle size="sm" pressed={false} onPressedChange={() => executeCommand(() => editor.chain().focus().redo().run())} disabled={!editor.can().redo() || disabled}>
            <Redo className="h-4 w-4" />
          </Toggle>
        </TooltipTrigger>
        <TooltipContent>
          <p>다시 실행 (Ctrl+Y)</p>
        </TooltipContent>
      </Tooltip>
    </>
  )
}


