const s = ({ menuData: u, moduleSelectedId: a, initialLevel: i = 0 }) => u.map((e) => {
  if (!e.children && e.moduleId === a)
    return { ...e, active: !0, itemInTreeActive: !1 };
  if (e.children) {
    let r = s({ menuData: e.children, moduleSelectedId: a, initialLevel: i + 1 });
    const n = r.findIndex((t) => t.active === !0);
    if (i === 0)
      return { ...e, children: r, active: !1, itemInTreeActive: !1 };
    n !== -1 && (r = r.map((t, f) => t.active ? { ...t, itemInTreeActive: !1 } : !t.active && !((t.children?.length ?? 0) > 0) ? { ...t, itemInTreeActive: !0, active: !1 } : f <= n ? {
      ...t,
      itemInTreeActive: !0,
      active: !1
    } : { ...t, itemInTreeActive: !1, active: !1 }));
    const c = n >= 0;
    return {
      ...e,
      children: r,
      itemInTreeActive: c,
      active: c && !!e.children
    };
  }
  return { ...e, active: !1, itemInTreeActive: !1 };
});
export {
  s as getMenuDataWithState
};
