"use client"

import { useState } from "react"
import { FolderInput } from "lucide-react"
import { Button } from "@/components/ui/button"
import { DriveMoveDialog } from "@/components/drive/drive-move-dialog"
import type { DriveFileInfo } from "@/lib/api/types"
import { buildMoveDestination } from "@/lib/drive/drive-move-items"

export function DocsMoveButton({
  file,
  onFileMoved,
}: {
  file: DriveFileInfo
  onFileMoved: (newPath: string) => void
}) {
  const [moveOpen, setMoveOpen] = useState(false)

  return (
    <>
      <Button
        type="button"
        variant="ghost"
        size="icon"
        className="size-7 shrink-0 text-muted-foreground"
        aria-label="Déplacer le document"
        title="Déplacer le document"
        onClick={() => setMoveOpen(true)}
      >
        <FolderInput className="size-4" />
      </Button>

      <DriveMoveDialog
        open={moveOpen}
        onOpenChange={setMoveOpen}
        sources={[file]}
        mode="move"
        onMoved={(destinationFolder) => {
          if (!destinationFolder) return
          onFileMoved(buildMoveDestination(destinationFolder, file.name))
        }}
      />
    </>
  )
}
