import React, { isValidElement, useState } from 'react';
import PropTypes from 'prop-types';
import { isEmpty } from 'lodash';
import matchSorter from 'match-sorter';
import Wrapper from './Wrapper';
import List from './List';
import LeftMenuLink from '../LeftMenuLink';
import LeftMenuSubList from '../LeftMenuSubList';
import LeftMenuHeader from '../LeftMenuHeader';
function LeftMenuList({ customLink, links, title, searchable }) {
const [search, setSearch] = useState('');
const { Component, componentProps } = customLink || {
Component: null,
componentProps: {},
};
const hasChildObject = () => links.some(link => !isEmpty(link.links));
const getCount = () => {
if (hasChildObject()) {
return links.reduce((acc, current) => {
return acc + current.links.length;
}, 0);
}
return links.length;
};
const getList = () => {
if (hasChildObject()) {
return links.map(link => {
return {
...link,
links: matchSorter(link.links, search, { keys: ['title'] }),
};
});
}
return matchSorter(links, search, { keys: ['title'] });
};
const renderCompo = (link, i) => {
const { links, name, title, ...rest } = link;
if (links) {
const isSearching = !isEmpty(search);
return (