'use client'
import { SquareCheckIcon, XIcon } from 'lucide-react'
import type { ReactNode } from 'react'
import { useContentPieceSelection } from '@/components/campaign/content/ContentPieceSelectionProvider'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/Checkbox'
import { cn } from '@/lib/utils'
/**
* C236 — the affordances of the selection mode (approved design scenes 1–3):
* the single entry at the top of the list, the mode badge with its exit, the
* per-row checkboxes of the table and the mobile card frame. All of them are
* client islands reading the one selection context; the table shell and the
* card bodies stay server-rendered.
*/
/** The opt-in entry ("Selecionar") and the active-mode chrome of the top of the list. */
export const ContentPieceSelectionModeControl = () => {
const { selectionMode, enterSelection, exitSelection, pendingAction } = useContentPieceSelection()
if (!selectionMode) {
return (
)
}
return (
Modo de seleção
)
}
/** The header checkbox: all of the visible page, or none. */
export const ContentPieceSelectAllCheckbox = () => {
const { allSelected, selectedCount, toggleAll, pendingAction } = useContentPieceSelection()
return (
0 ? 'indeterminate' : false}
onCheckedChange={() => toggleAll()}
disabled={pendingAction !== null}
aria-label="Selecionar todas as peças desta página"
/>
)
}
/**
* One table-row checkbox. The wrapper carries `data-selection-state`, which the
* row's `has-[…]:bg-primary/5` class uses to tint the selected line.
*/
export const ContentPieceRowCheckbox = ({
contentPieceId,
title,
}: {
contentPieceId: number
title: string
}) => {
const { isSelected, toggle, pendingAction } = useContentPieceSelection()
const selected = isSelected(contentPieceId)
return (
toggle(contentPieceId)}
disabled={pendingAction !== null}
aria-label={`Selecionar ${title}`}
/>
)
}
/**
* The mobile card frame (design scene 3b): in selection mode the article gains
* the 44px touch target with the checkbox and the primary ring; outside it the
* frame renders the exact resting article, so the card look at rest does not
* depend on this island. `header` is the card's title/meta block (which sits
* beside the checkbox); children are the rest of the card body.
*/
export const ContentPieceCardSelectionFrame = ({
contentPieceId,
title,
header,
children,
}: {
contentPieceId: number
title: string
header: ReactNode
children: ReactNode
}) => {
const { selectionMode, isSelected, toggle, pendingAction } = useContentPieceSelection()
const selected = selectionMode && isSelected(contentPieceId)
if (!selectionMode) {
return (
{header}
{children}
)
}
return (