import { ICollection } from '@hyral/core'; import { IMenu } from '../__types__'; export default (collection: ICollection): unknown[] => { if (!collection || !collection.data) { return []; } const list = collection.data.map((item) => ({ ...item.data, children: [], id: item.id })); list .filter((item) => item.parent !== '') .forEach((item) => list.find((rootItem) => rootItem.id === item.parent)?.children.push(item as never)); return list.filter((item) => item.parent === ''); };