import { useLocal } from "@/lib/utils/use-local"; import { useEffect } from "react"; import { v4 as uuidv4 } from "uuid"; export const PinterestLayout: React.FC<{ data: any[]; child: (item: any, index: any, data: any[], key?: string) => any; col: number; gap?: number; }> = ({ data, child, col = 2, gap = 2 }) => { function generateUUIDs(data: any[]): string[] { return data.map(() => uuidv4()); } const createColumns = (items: any[], numCols: number) => { const columns: any = Array.from({ length: numCols }, () => []); // Membuat array kosong sebanyak jumlah kolom items.forEach((item, index) => { columns[index % numCols].push(item); // Memasukkan item ke dalam kolom secara berurutan }); return columns; }; const local = useLocal({ data: [] as any[], ids: { col: [] as string[], data: [] as string[], }, user: null as any, ready: false as boolean, }); useEffect(() => { const columns: any[] = Array.from({ length: col }, () => []); if (Array.isArray(data) && data?.length) data.forEach((item, index) => { const targetColumn = index % col; // Menentukan kolom target berdasarkan indeks columns[targetColumn].push(item); // Memasukkan elemen ke kolom yang sesuai }); local.data = columns; local.render(); }, [data, col]); return ( <>