"use client"

import * as React from "react"
import { type Table } from "@tanstack/react-table"
import { Download, RefreshCcw } from "lucide-react"
import { toast } from "sonner"

import { exportTableToExcel } from "@/lib/export"
import { Button } from "@/components/ui/button"
import { VendorPO } from "./types"

interface ShiVendorPOToolbarActionsProps {
  table: Table<VendorPO>
  selectedRows: number[]
  onAction: (poId: number, action: string) => Promise<void>
  onViewItems: (po: VendorPO) => void
}

export function ShiVendorPOToolbarActions({ 
  table, 
  selectedRows,
  onAction,
  onViewItems 
}: ShiVendorPOToolbarActionsProps) {

  const handleRefresh = async () => {
    try {
      toast.success("데이터를 새로고침했습니다.")
      // TODO: 실제 데이터 새로고침 로직 추가
      window.location.reload()
    } catch (error) {
      toast.error("데이터 새로고침 중 오류가 발생했습니다.")
    }
  }

  return (
    <div className="flex items-center gap-2">
      {/* Refresh 버튼 */}
      <Button
        variant="samsung"
        size="sm"
        className="gap-2"
        onClick={handleRefresh}
      >
        <RefreshCcw className="size-4" aria-hidden="true" />
        <span className="hidden sm:inline">Refresh</span>
      </Button>

      {/* Export 버튼 */}
      <Button
        variant="outline"
        size="sm"
        onClick={() =>
          exportTableToExcel(table, {
            filename: "vendor-po-list",
            excludeColumns: ["select", "actions"],
          })
        }
        className="gap-2"
      >
        <Download className="size-4" aria-hidden="true" />
        <span className="hidden sm:inline">Export</span>
      </Button>
    </div>
  )
}
