2026-02-03 17:20:38 +07:00
|
|
|
'use client';
|
|
|
|
|
import { useState, useMemo } from "react";
|
|
|
|
|
|
2026-02-02 16:42:40 +07:00
|
|
|
import { CommentData } from "@/data/comments";
|
|
|
|
|
import Form from "./Form";
|
|
|
|
|
import CommentList from "./CommentList";
|
|
|
|
|
|
|
|
|
|
export default function Comment() {
|
2026-02-03 17:20:38 +07:00
|
|
|
const [star, setStar] = useState<number | null>(null);
|
|
|
|
|
|
2026-02-05 17:22:56 +07:00
|
|
|
const productComment = CommentData.list.filter( (item:any) => item.item_type === "product" );
|
|
|
|
|
|
2026-02-03 17:20:38 +07:00
|
|
|
const filteredComments = useMemo(() => {
|
2026-02-05 17:22:56 +07:00
|
|
|
if (star === null) return productComment;
|
|
|
|
|
return productComment.filter(item => Number(item.rate) === star);
|
2026-02-03 17:20:38 +07:00
|
|
|
}, [star]);
|
2026-02-02 16:42:40 +07:00
|
|
|
|
2026-02-05 17:22:56 +07:00
|
|
|
|
2026-02-02 16:42:40 +07:00
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<div className="flex items-center justify-between leading-8 gap-2 mb-4">
|
2026-02-05 17:22:56 +07:00
|
|
|
<p className="m-0 text-18 font-500"> {filteredComments.length} Bình luận </p>
|
2026-02-02 16:42:40 +07:00
|
|
|
|
|
|
|
|
<div className="flex flex-wrap gap-2 text-14 font-500 pd-comment-btn">
|
2026-02-03 17:20:38 +07:00
|
|
|
<button type="button"
|
|
|
|
|
className={`h-8 border rounded-[40px] px-8
|
|
|
|
|
${star === null ? 'border-[#0678DB] text-[#0678DB]' : 'border-[#D1D5DB]'}`}
|
|
|
|
|
onClick={() => setStar(null)}
|
|
|
|
|
>
|
|
|
|
|
Tất cả
|
|
|
|
|
</button>
|
2026-02-02 16:42:40 +07:00
|
|
|
|
2026-02-03 17:20:38 +07:00
|
|
|
{[5,4,3,2,1].map(s => (
|
|
|
|
|
<button type="button"
|
|
|
|
|
key={s}
|
|
|
|
|
className={`h-8 border rounded-[40px] px-4 flex items-center gap-[3px]
|
|
|
|
|
${star === s ? 'border-[#0678DB] text-[#0678DB]' : 'border-[#D1D5DB]'}`}
|
|
|
|
|
onClick={() => setStar(s)}
|
|
|
|
|
>
|
|
|
|
|
{s} <i className="bxr bx-star" />
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
2026-02-02 16:42:40 +07:00
|
|
|
</div>
|
2026-02-03 17:20:38 +07:00
|
|
|
|
2026-02-02 16:42:40 +07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="border border-[#DDDDDD] rounded-[12px] overflow-hidden js-comment-form">
|
|
|
|
|
<Form />
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-02-03 17:20:38 +07:00
|
|
|
{filteredComments.length > 0 && (
|
|
|
|
|
<CommentList item={filteredComments} />
|
|
|
|
|
)}
|
2026-02-02 16:42:40 +07:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|