From 1110427907bbe9c11a378da4c1a233b83b5ca3b1 Mon Sep 17 00:00:00 2001
From: joonhoekim <26rote@gmail.com>
Date: Tue, 26 Aug 2025 12:09:39 +0000
Subject: (김준회) 구매정의서 구현 - PO (shi & vendor)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/po/vendor-table/vendor-po-toolbar-actions.tsx | 214 ++++++++++++++++++++++
 1 file changed, 214 insertions(+)
 create mode 100644 lib/po/vendor-table/vendor-po-toolbar-actions.tsx

(limited to 'lib/po/vendor-table/vendor-po-toolbar-actions.tsx')

diff --git a/lib/po/vendor-table/vendor-po-toolbar-actions.tsx b/lib/po/vendor-table/vendor-po-toolbar-actions.tsx
new file mode 100644
index 00000000..800a9e40
--- /dev/null
+++ b/lib/po/vendor-table/vendor-po-toolbar-actions.tsx
@@ -0,0 +1,214 @@
+"use client"
+
+import * as React from "react"
+import { type Table } from "@tanstack/react-table"
+import {
+  EyeIcon,
+  EditIcon,
+  FileXIcon,
+  PrinterIcon,
+} from "lucide-react"
+
+import { Button } from "@/components/ui/button"
+import {
+  DropdownMenu,
+  DropdownMenuContent,
+  DropdownMenuItem,
+  DropdownMenuLabel,
+  DropdownMenuSeparator,
+  DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu"
+import {
+  Tooltip,
+  TooltipContent,
+  TooltipProvider,
+  TooltipTrigger,
+} from "@/components/ui/tooltip"
+import { toast } from "sonner"
+import { VendorPO } from "./types"
+
+interface VendorPOToolbarActionsProps {
+  table: Table<VendorPO>
+  selectedRows: number[]
+  onAction: (poId: number, action: string) => Promise<void>
+  onViewItems?: (po: VendorPO) => void
+}
+
+export function VendorPOToolbarActions({ 
+  table, 
+  selectedRows, 
+  onAction,
+  onViewItems
+}: VendorPOToolbarActionsProps) {
+  const hasSelectedRow = selectedRows.length === 1
+  const selectedPO = hasSelectedRow ? 
+    table.getRowModel().rows.find(row => selectedRows.includes(row.original.id))?.original 
+    : null
+
+  const handleToolbarAction = async (action: string) => {
+    if (!hasSelectedRow || !selectedPO) {
+      toast.error("먼저 PO를 선택해주세요.")
+      return
+    }
+
+    // view-items 액션은 특별히 처리
+    if (action === "view-items") {
+      if (onViewItems) {
+        onViewItems(selectedPO)
+      }
+      return
+    }
+
+    await onAction(selectedPO.id, action)
+  }
+
+  return (
+    <div className="flex items-center gap-2">
+      {/* 주요 액션 버튼들 */}
+      <TooltipProvider>
+        <Tooltip>
+          <TooltipTrigger asChild>
+                          <Button
+                variant="default"
+                size="sm"
+                onClick={() => handleToolbarAction("pcr-create")}
+                disabled={!hasSelectedRow}
+                className="h-8"
+              >
+                PCR생성
+              </Button>
+          </TooltipTrigger>
+          <TooltipContent>선택된 PO에 대한 PCR을 생성합니다</TooltipContent>
+        </Tooltip>
+      </TooltipProvider>
+
+      <TooltipProvider>
+        <Tooltip>
+          <TooltipTrigger asChild>
+            <Button
+              variant="outline"
+              size="sm"
+              onClick={() => handleToolbarAction("view-items")}
+              disabled={!hasSelectedRow}
+              className="h-8"
+            >
+              상세품목현황
+            </Button>
+          </TooltipTrigger>
+          <TooltipContent>상세품목 현황을 확인합니다</TooltipContent>
+        </Tooltip>
+      </TooltipProvider>
+
+      {/* 승인 관련 액션 */}
+      {selectedPO?.contractStatus !== "승인완료" && (
+        <TooltipProvider>
+          <Tooltip>
+            <TooltipTrigger asChild>
+              <Button
+                variant="outline"
+                size="sm"
+                onClick={() => handleToolbarAction("approve")}
+                disabled={!hasSelectedRow}
+                className="h-8 text-green-600 border-green-600 hover:bg-green-50"
+              >
+                승인
+              </Button>
+            </TooltipTrigger>
+            <TooltipContent>선택된 계약을 승인합니다</TooltipContent>
+          </Tooltip>
+        </TooltipProvider>
+      )}
+
+      {selectedPO?.contractStatus === "승인완료" && (
+        <TooltipProvider>
+          <Tooltip>
+            <TooltipTrigger asChild>
+              <Button
+                variant="outline"
+                size="sm"
+                onClick={() => handleToolbarAction("cancel-approve")}
+                disabled={!hasSelectedRow}
+                className="h-8 text-orange-600 border-orange-600 hover:bg-orange-50"
+              >
+                승인취소
+              </Button>
+            </TooltipTrigger>
+            <TooltipContent>승인을 취소합니다</TooltipContent>
+          </Tooltip>
+        </TooltipProvider>
+      )}
+
+      {/* 더 많은 액션 드롭다운 */}
+      <DropdownMenu>
+        <DropdownMenuTrigger asChild>
+          <Button
+            variant="outline"
+            size="sm"
+            disabled={!hasSelectedRow}
+            className="h-8"
+          >
+            더 많은 액션
+          </Button>
+        </DropdownMenuTrigger>
+        <DropdownMenuContent align="end" className="w-[200px]">
+          <DropdownMenuLabel>계약 관련</DropdownMenuLabel>
+          <DropdownMenuSeparator />
+          
+          <DropdownMenuItem
+            onClick={() => handleToolbarAction("contract-detail")}
+            disabled={!hasSelectedRow}
+          >
+            <EyeIcon className="mr-2 h-4 w-4" />
+            계약상세
+          </DropdownMenuItem>
+          
+          <DropdownMenuItem
+            onClick={() => handleToolbarAction("po-note")}
+            disabled={!hasSelectedRow}
+          >
+            <EditIcon className="mr-2 h-4 w-4" />
+            PO Note
+          </DropdownMenuItem>
+          
+          <DropdownMenuItem
+            onClick={() => handleToolbarAction("price-index")}
+            disabled={!hasSelectedRow}
+          >
+            <EditIcon className="mr-2 h-4 w-4" />
+            연동표입력
+          </DropdownMenuItem>
+
+          <DropdownMenuSeparator />
+          
+          <DropdownMenuItem
+            onClick={() => handleToolbarAction("reject-contract")}
+            disabled={!hasSelectedRow}
+            className="text-red-600 focus:text-red-600"
+          >
+            <FileXIcon className="mr-2 h-4 w-4" />
+            계약거절
+          </DropdownMenuItem>
+          
+          <DropdownMenuSeparator />
+          
+          <DropdownMenuItem
+            onClick={() => handleToolbarAction("print-contract")}
+            disabled={!hasSelectedRow}
+          >
+            <PrinterIcon className="mr-2 h-4 w-4" />
+            계약서출력
+          </DropdownMenuItem>
+        </DropdownMenuContent>
+      </DropdownMenu>
+
+      {/* 선택된 행 정보 표시
+      {hasSelectedRow && selectedPO && (
+        <div className="flex items-center gap-2 ml-4 text-sm text-muted-foreground">
+          <span>선택됨:</span>
+          <span className="font-medium">{selectedPO.contractNo}</span>
+          <span>({selectedPO.contractName})</span>
+        </div>
+      )} */}
+    </div>
+  )
+}
-- 
cgit v1.2.3

