2026-01-28 17:26:02 +07:00
|
|
|
|
|
|
|
|
'use client';
|
2026-01-30 17:09:41 +07:00
|
|
|
import { useEffect, useState } from 'react'
|
2026-01-28 17:26:02 +07:00
|
|
|
|
|
|
|
|
export default function ProductSummary({ item }: any) {
|
2026-01-30 17:09:41 +07:00
|
|
|
const [mounted, setMounted] = useState(false)
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setMounted(true)
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
if (!mounted) return null
|
|
|
|
|
|
|
|
|
|
|
2026-01-28 17:26:02 +07:00
|
|
|
return (
|
|
|
|
|
<div className="mb-3 pd-summary-group">
|
|
|
|
|
<p className="leading-6 mb-2 text-16 font-600"> Thông số sản phẩm </p>
|
|
|
|
|
|
|
|
|
|
<div> {renderSummary(item)}</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-01-30 17:09:41 +07:00
|
|
|
function renderSummary(data: any) {
|
2026-01-28 17:26:02 +07:00
|
|
|
if (!data) return null;
|
|
|
|
|
|
|
|
|
|
if (typeof data === 'string' && data.includes('<')) {
|
2026-01-30 17:09:41 +07:00
|
|
|
const parser = new DOMParser()
|
|
|
|
|
const doc = parser.parseFromString(data, 'text/html')
|
2026-01-28 17:26:02 +07:00
|
|
|
|
|
|
|
|
return Array.from(doc.body.childNodes)
|
|
|
|
|
.filter(
|
|
|
|
|
node =>
|
2026-01-30 17:09:41 +07:00
|
|
|
node.nodeType === 1 &&
|
|
|
|
|
node.textContent &&
|
|
|
|
|
node.textContent.trim() !== ''
|
2026-01-28 17:26:02 +07:00
|
|
|
)
|
|
|
|
|
.map((node, index) => (
|
|
|
|
|
<div key={index} className="item-circle">
|
2026-01-30 17:09:41 +07:00
|
|
|
{node.textContent!.trim()}
|
2026-01-28 17:26:02 +07:00
|
|
|
</div>
|
2026-01-30 17:09:41 +07:00
|
|
|
))
|
2026-01-28 17:26:02 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
.split(/\r?\n/)
|
2026-01-30 17:09:41 +07:00
|
|
|
.filter((line: string) => line.trim() !== '')
|
|
|
|
|
.map((line: string, index: number) => (
|
2026-01-28 17:26:02 +07:00
|
|
|
<div key={index} className="item-circle">
|
|
|
|
|
{line.trim()}
|
|
|
|
|
</div>
|
2026-01-30 17:09:41 +07:00
|
|
|
))
|
2026-01-28 17:26:02 +07:00
|
|
|
}
|