'use client';
import { useEffect, useState } from 'react'
export default function ProductSummary({ item }: any) {
const [mounted, setMounted] = useState(false)
useEffect(() => {
setMounted(true)
}, [])
if (!mounted) return null
return (
Thông số sản phẩm
{renderSummary(item)}
)
}
function renderSummary(data: any) {
if (!data) return null;
if (typeof data === 'string' && data.includes('<')) {
const parser = new DOMParser()
const doc = parser.parseFromString(data, 'text/html')
return Array.from(doc.body.childNodes)
.filter(
node =>
node.nodeType === 1 &&
node.textContent &&
node.textContent.trim() !== ''
)
.map((node, index) => (
{node.textContent!.trim()}
))
}
return data
.split(/\r?\n/)
.filter((line: string) => line.trim() !== '')
.map((line: string, index: number) => (
{line.trim()}
))
}