/*
Copyright (C) 2023-2026 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
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')}