import * as React from "react" import { cva, type VariantProps } from "class-variance-authority" import { cn } from "@/lib/utils" const dataTableToolbarVariants = cva("flex flex-col", { variants: { variant: { default: "rounded-lg border border-border bg-card shadow-sm", plain: "border-transparent bg-transparent shadow-none", soft: "rounded-lg border border-border bg-muted shadow-none", }, density: { compact: "gap-3 p-3", default: "gap-4 p-4 md:p-5", comfortable: "gap-5 p-5 md:p-6", }, }, defaultVariants: { variant: "plain", density: "default", }, }) export type DataTableToolbarProps = React.ComponentProps<"div"> & VariantProps & { title?: React.ReactNode description?: React.ReactNode search?: React.ReactNode filters?: React.ReactNode summary?: React.ReactNode actions?: React.ReactNode selectionActions?: React.ReactNode selectedCount?: number totalCount?: number selectedLabel?: (selectedCount: number, totalCount?: number) => React.ReactNode titleClassName?: string descriptionClassName?: string searchClassName?: string filtersClassName?: string summaryClassName?: string actionsClassName?: string } function DataTableToolbar({ className, variant, density, title, description, search, filters, summary, actions, selectionActions, selectedCount = 0, totalCount, selectedLabel = (selected, total) => total === undefined ? `${selected} selected` : `${selected} of ${total} selected`, titleClassName, descriptionClassName, searchClassName, filtersClassName, summaryClassName, actionsClassName, children, ...props }: DataTableToolbarProps) { const hasHeading = Boolean(title || description) const hasSelection = selectedCount > 0 && Boolean(selectionActions) const hasMainControls = Boolean(search || filters || children) return (
{(hasHeading || actions) && (
{hasHeading && (
{title &&

{title}

} {description &&

{description}

}
)} {actions &&
{actions}
}
)} {(hasMainControls || summary || hasSelection) && (
{hasMainControls && (
{search ?
{search}
: null}
{filters ?
*]:min-w-0", filtersClassName)}>{filters}
: null} {children}
)} {summary ? (
{summary}
) : null}
{hasSelection && (
{selectedLabel(selectedCount, totalCount)} {selectionActions}
)}
)}
) } export { DataTableToolbar, dataTableToolbarVariants }