"use client"

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

import { ComboBoxOptionsAddDialog } from "@/lib/docu-list-rule/combo-box-settings/table/combo-box-options-add-dialog"
import { DeleteComboBoxOptionsDialog } from "@/lib/docu-list-rule/combo-box-settings/table/delete-combo-box-options-dialog"

interface ComboBoxOption {
  id: number
  codeGroupId: number
  code: string
  description: string
  remark: string | null
  isActive: boolean
  createdAt: Date
  updatedAt: Date
}

interface ComboBoxOptionsTableToolbarActionsProps {
  table: Table<ComboBoxOption>
  codeGroupId: number
  onSuccess?: () => void
}

export function ComboBoxOptionsTableToolbarActions({
  table,
  codeGroupId,
  onSuccess,
}: ComboBoxOptionsTableToolbarActionsProps) {
  const selectedRows = table.getFilteredSelectedRowModel().rows
  const selectedOptions = selectedRows.map((row) => row.original)

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

      <ComboBoxOptionsAddDialog
        codeGroupId={codeGroupId}
        onSuccess={onSuccess}
      />
    </div>
  )
} 