import s from './styles.module.scss';
import Image from 'next/image';
import dtrLogo from '@public/images/dtr-logo-eagle.png';
import { baseMenu, TMenu } from '@core/constants/menu';
import { Icons } from '@shared/ui/icon';
import Link from 'next/link';

function BaseMenu() {
  const Menu = ({ list }: { list: TMenu }) => {
    const nodeList = (list: TMenu) => {
      return list.map((item, index) => {
        if (item.children && item.children.length) {
          return (
            <li key={index} className={s.Parent}>
              <div className={s.Row}>
                {item.name}
                <Icons.MenuArrow className={s.Expand} />
              </div>
              <ul className={s.Child}>{nodeList(item.children)}</ul>
            </li>
          );
        }

        return (
          <li key={index}>
            <Link href={item.link!}>{item.name}</Link>
          </li>
        );
      });
    };
    return (
      <nav className={s.Nav}>
        <ul className={s.Menu}>{nodeList(list)}</ul>
      </nav>
    );
  };

  return (
    <section className={s.ContainerNavbar}>
      <div className={s.Navbar}>
        <Image src={dtrLogo} alt={'ДиТрасо'} quality={75} priority />
        <Menu list={baseMenu} />
        <div className={s.Invite}>
          <button>+7 (999) 123-45-67</button>
        </div>
      </div>
    </section>
  );
}

export { BaseMenu };
