import { useState } from 'react' import { useQueryClient } from '@tanstack/react-query' import { type Table } from '@tanstack/react-table' import { Power, PowerOff, Tag, Trash2 } from 'lucide-react' import { useTranslation } from 'react-i18next' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Tooltip, TooltipContent, TooltipTrigger, } from '@/components/ui/tooltip' import { DataTableBulkActions as BulkActionsToolbar } from '@/components/data-table' import { handleBatchDelete, handleBatchDisable, handleBatchEnable, handleBatchSetTag, } from '../lib' import type { Channel } from '../types' interface DataTableBulkActionsProps { table: Table } export function DataTableBulkActions({ table, }: DataTableBulkActionsProps) { const { t } = useTranslation() const queryClient = useQueryClient() const [showTagDialog, setShowTagDialog] = useState(false) const [showDeleteConfirm, setShowDeleteConfirm] = useState(false) const [tagValue, setTagValue] = useState('') const selectedRows = table.getFilteredSelectedRowModel().rows const selectedIds = selectedRows.reduce((ids, row) => { const id = (row.original as Channel).id if (typeof id === 'number') { ids.push(id) } return ids }, []) const handleClearSelection = () => { table.resetRowSelection() } const handleEnableAll = () => { handleBatchEnable(selectedIds, queryClient, handleClearSelection) } const handleDisableAll = () => { handleBatchDisable(selectedIds, queryClient, handleClearSelection) } const handleDeleteAll = () => { handleBatchDelete(selectedIds, queryClient, () => { setShowDeleteConfirm(false) handleClearSelection() }) } const handleSetTag = () => { handleBatchSetTag(selectedIds, tagValue || null, queryClient, () => { setShowTagDialog(false) setTagValue('') handleClearSelection() }) } return ( <> } > {t('Enable selected channels')}

{t('Enable selected channels')}

} > {t('Disable selected channels')}

{t('Disable selected channels')}

setShowTagDialog(true)} className='size-8' aria-label={t('Set tag for selected channels')} title={t('Set tag for selected channels')} /> } > {t('Set tag for selected channels')}

{t('Set tag for selected channels')}

setShowDeleteConfirm(true)} className='size-8' aria-label={t('Delete selected channels')} title={t('Delete selected channels')} /> } > {t('Delete selected channels')}

{t('Delete selected channels')}

{/* Set Tag Dialog */} {t('Set Tag')} {t('Set a tag for')} {selectedIds.length}{' '} {t('selected channel(s). Leave empty to remove tag.')}
setTagValue(e.target.value)} />
{/* Delete Confirmation Dialog */} {t('Delete Channels?')} {t('Are you sure you want to delete')} {selectedIds.length}{' '} {t('channel(s)? This action cannot be undone.')} ) }