import * as React from 'react' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { AdminActionDialog, type StatusTone } from '@/components/admin' export type BatchActionId = 'hide' | 'delete' | 'restore' | string export interface BatchActionConfig { id: BatchActionId label: string /** When true, the confirmation requires a note before submit. */ destructive?: boolean tone?: StatusTone confirmTitle: string confirmDescription: string confirmLabel?: string } interface BatchOperationsToolbarProps { selectedCount: number totalCount?: number onSelectAll?: () => void onClearSelection?: () => void actions: BatchActionConfig[] onAction: (action: BatchActionConfig, remark: string) => void isLoading?: boolean pendingAction?: BatchActionId | null } export function BatchOperationsToolbar({ selectedCount, totalCount, onSelectAll, onClearSelection, actions, onAction, isLoading = false, pendingAction = null, }: BatchOperationsToolbarProps) { const [pending, setPending] = React.useState(null) const [remark, setRemark] = React.useState('') if (selectedCount === 0) return null function handleConfirm() { if (!pending) return if (pending.destructive && !remark.trim()) { return } onAction(pending, remark.trim()) setPending(null) setRemark('') } return ( <>
Selected {selectedCount} {typeof totalCount === 'number' ? ` / ${totalCount}` : ''} {onSelectAll && ( )} {onClearSelection && ( )}
{actions.map((action) => ( ))}
{ if (!open) { setPending(null) setRemark('') } }} tone={pending?.tone ?? (pending?.destructive ? 'danger' : 'info')} title={pending?.confirmTitle ?? 'Confirm bulk action'} description={pending?.confirmDescription ?? ''} confirmLabel={pending?.confirmLabel ?? 'Confirm'} isLoading={isLoading && pendingAction === pending?.id} onConfirm={handleConfirm} > {pending?.destructive ? (