"use client"

import * as React from "react"
import { type Table } from "@tanstack/react-table"

import { DocumentClassOptionAddDialog } from "@/lib/docu-list-rule/document-class/table/document-class-option-add-dialog"
import { DeleteDocumentClassOptionDialog } from "@/lib/docu-list-rule/document-class/table/delete-document-class-option-dialog"
import { documentClassOptions } from "@/db/schema/docu-list-rule"

interface DocumentClassOptionsTableToolbarActionsProps {
  table: Table<typeof documentClassOptions.$inferSelect>
  documentClassId: number
  onSuccess?: () => void
}

export function DocumentClassOptionsTableToolbarActions({
  table,
  documentClassId,
  onSuccess,
}: DocumentClassOptionsTableToolbarActionsProps) {
  const selectedRows = table.getFilteredSelectedRowModel().rows
  const selectedOptions = selectedRows.map((row) => row.original)

  return (
    <div className="flex items-center gap-2">
      {/** 선택된 로우가 있으면 삭제 다이얼로그 */}
      {selectedOptions.length > 0 ? (
        <DeleteDocumentClassOptionDialog
          options={selectedOptions}
          onSuccess={() => {
            table.toggleAllRowsSelected(false)
            onSuccess?.()
          }}
        />
      ) : null}

      <DocumentClassOptionAddDialog
        documentClassId={documentClassId}
        onSuccess={onSuccess}
      />
    </div>
  )
} 