// import

import { useEffect } from 'react';
import { sectionNavigation } from '@vendor-web/js/components/sectionNavigation.js'
import NavigationWrapper from '@/components/aia/navigation-wrapper';

type Props = {
  links: {
    name: string;
    href: string;
    default?: boolean;
  }[];

}


export default function SectionNavigation(
  { links = [] }: Props
) {

  useEffect(() => {
    sectionNavigation();
  }, []);

  return (


    <NavigationWrapper className="sectionNavigation pageSectionNavigation">
      <div className="container sectionNavigation-container">
        <div className="sectionNavigation-selectContainer">
          <select
            className="sectionNavigation-select"
            name="sectionNavigation"
            id="sectionNavigation"
            defaultValue={links.find(link => link.default)?.href || ''} // Default to the first link if no default is set
            onChange={(e) => {
              const selectedHref = e.target.value;
              window.location.href = selectedHref;
            }}
          >

            {
              links.map(
                (link, index) => (
                  <option
                    key={index}
                    value={link.href}
                  >
                    {link.name}
                  </option>
                )
              )

            }

          </select>
          <i className="icon-arrowDown sectionNavigation-selectIcon"></i>
        </div>
        <nav className="sectionNavigation-navContainer">
          <ul className="sectionNavigation-navList">
            {links.map(
              (
                link,
                index
              ) => (
                <li
                  key={index}
                  className={
                    link.default ? 'sectionNavigation-active' : ''
                  }
                >
                  <a href={link.href}>
                    {link.name}
                  </a>
                </li>))}
          </ul>
        </nav>
      </div>
    </NavigationWrapper>

  );
}
