import Link from '@components/atoms/links/link';
import NavLink from '@components/atoms/links/nav-link';
import { FC, ReactNode } from 'react';
import styles from './nav.module.scss';

export type NavItem = {
  /**
   * The item id.
   */
  id: string;
  /**
   * The item link.
   */
  href: string;
  /**
   * The item name.
   */
  label: string;
  /**
   * The item logo.
   */
  logo?: ReactNode;
};

export type NavProps = {
  /**
   * An accessible name.
   */
  'aria-label'?: string;
  /**
   * Set additional classnames to the navigation wrapper.
   */
  className?: string;
  /**
   * The navigation items.
   */
  items: NavItem[];
  /**
   * The navigation kind.
   */
  kind: 'main' | 'footer';
  /**
   * Set additional classnames to the navigation list.
   */
  listClassName?: string;
};

/**
 * Nav component
 *
 * Render the nav links.
 */
const Nav: FC<NavProps> = ({
  className = '',
  items,
  kind,
  listClassName = '',
  ...props
}) => {
  const kindClass = `nav--${kind}`;

  /**
   * Get the nav items.
   * @returns {JSX.Element[]} An array of nav items.
   */
  const getItems = (): JSX.Element[] => {
    return items.map(({ id, href, label, logo }) => (
      <li key={id} className={styles.nav__item}>
        {kind === 'main' ? (
          <NavLink href={href} label={label} logo={logo} />
        ) : (
          <Link href={href}>{label}</Link>
        )}
      </li>
    ));
  };

  return (
    <nav className={`${styles[kindClass]} ${className}`} {...props}>
      <ul className={`${styles.nav__list} ${listClassName}`}>{getItems()}</ul>
    </nav>
  );
};

export default Nav;
rmandphilippot.com/log/src/components/atoms/visually-hidden/visually-hidden.module.scss'>log</a><a class='active' href='/www.armandphilippot.com/tree/src/components/atoms/visually-hidden/visually-hidden.module.scss?id=b0ebd69d5b5f6dfed4e82528dff1b913a4240dc8'>tree</a><a href='/www.armandphilippot.com/commit/src/components/atoms/visually-hidden/visually-hidden.module.scss?id=b0ebd69d5b5f6dfed4e82528dff1b913a4240dc8'>commit</a><a href='/www.armandphilippot.com/diff/src/components/atoms/visually-hidden/visually-hidden.module.scss?id=b0ebd69d5b5f6dfed4e82528dff1b913a4240dc8'>diff</a><a href='/www.armandphilippot.com/stats/src/components/atoms/visually-hidden/visually-hidden.module.scss'>stats</a></td><td class='form'><form class='right' method='get' action='/www.armandphilippot.com/log/src/components/atoms/visually-hidden/visually-hidden.module.scss'>
<input type='hidden' name='id' value='b0ebd69d5b5f6dfed4e82528dff1b913a4240dc8'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/www.armandphilippot.com/tree/?id=b0ebd69d5b5f6dfed4e82528dff1b913a4240dc8'>root</a>/<a href='/www.armandphilippot.com/tree/src?id=b0ebd69d5b5f6dfed4e82528dff1b913a4240dc8'>src</a>/<a href='/www.armandphilippot.com/tree/src/components?id=b0ebd69d5b5f6dfed4e82528dff1b913a4240dc8'>components</a>/<a href='/www.armandphilippot.com/tree/src/components/atoms?id=b0ebd69d5b5f6dfed4e82528dff1b913a4240dc8'>atoms</a>/<a href='/www.armandphilippot.com/tree/src/components/atoms/visually-hidden?id=b0ebd69d5b5f6dfed4e82528dff1b913a4240dc8'>visually-hidden</a>/<a href='/www.armandphilippot.com/tree/src/components/atoms/visually-hidden/visually-hidden.module.scss?id=b0ebd69d5b5f6dfed4e82528dff1b913a4240dc8'>visually-hidden.module.scss</a></div><div class='content'>blob: c61661524bbc83a1ed4a8127da213f675af59f56 (<a href='/www.armandphilippot.com/plain/src/components/atoms/visually-hidden/visually-hidden.module.scss?id=b0ebd69d5b5f6dfed4e82528dff1b913a4240dc8'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
<a id='n2' href='#n2'>2</a>
<a id='n3' href='#n3'>3</a>
<a id='n4' href='#n4'>4</a>
<a id='n5' href='#n5'>5</a>
<a id='n6' href='#n6'>6</a>
<a id='n7' href='#n7'>7</a>
</pre></td>
<td class='lines'><pre><code>