"use client"

import { type Table } from "@tanstack/react-table"
import { Download } from "lucide-react"

import { Button } from "@/components/ui/button"

import { type GtcDocumentWithRelations } from "@/db/schema/gtc"
import { CreateGtcDocumentDialog } from "./create-gtc-document-dialog"
import { exportTableToExcel } from "@/lib/export"

interface GtcDocumentsTableToolbarActionsProps {
  table: Table<GtcDocumentWithRelations>
}

export function GtcDocumentsTableToolbarActions({
  table,
}: GtcDocumentsTableToolbarActionsProps) {
  return (
    <div className="flex items-center gap-2">
      {table.getFilteredSelectedRowModel().rows.length > 0 ? (
        <Button
          variant="outline"
          size="sm"
          onClick={() =>
            exportTableToExcel(table, {
              filename: "gtc-documents",
              excludeColumns: ["select", "actions"],
            })
          }
        >
          <Download className="mr-2 size-4" aria-hidden="true" />
          Export ({table.getFilteredSelectedRowModel().rows.length})
        </Button>
      ) : null}
      <CreateGtcDocumentDialog />
    </div>
  )
}