/**
* BoostMedia AI Content Generator Admin - Expandable Summary Component
*
* Truncates text to N words with expand/collapse on click.
*
* @package BoostMedia_AI
* @license GPL-2.0-or-later
*/
import { useState } from 'react'
import { t } from '../../lib/i18n'
interface ExpandableSummaryProps {
text: string | null
wordLimit?: number
className?: string
}
export function ExpandableSummary({ text, wordLimit = 10, className = '' }: ExpandableSummaryProps) {
const [expanded, setExpanded] = useState(false)
if (!text || text.trim() === '' || text === '—') {
return —
}
const words = text.split(/\s+/)
const isLong = words.length > wordLimit
const displayText = expanded || !isLong
? text
: words.slice(0, wordLimit).join(' ') + '…'
return (
isLong && setExpanded(!expanded)}
title={isLong && !expanded ? t('Click to expand') : undefined}
>
{displayText}
)
}