---
interface NavItem {
  id: string;
  title: string;
  url: string;
  is_visible: boolean;
  order: number;
  target_blank?: boolean;
}

interface Props {
  items?: NavItem[];
  currentPath?: string;
}

const { items, currentPath = '/' }: Props = Astro.props;
const navItems: NavItem[] = items || [];

// Нормализация путей
const normalize = (path: string) => path.replace(/\/$/, '') || '/';
const normalizedCurrentPath = normalize(currentPath);
---

<nav class="flex items-center gap-x-6">
  {
    navItems
      .filter((item) => {
        // Скрываем пункт "Главная" на главной странице
        const itemUrl = normalize(item.url);
        if (itemUrl === '/' && normalizedCurrentPath === '/') {
          return false;
        }
        return true;
      })
      .map((item) => {
        const itemUrl = normalize(item.url);

        const isActive = itemUrl === '/'
          ? normalizedCurrentPath === '/'
          : normalizedCurrentPath.startsWith(itemUrl);

        return (
          <a
            href={item.url}
            target={item.target_blank ? "_blank" : "_self"}
            class:list={[
              "text-lg font-medium transition-colors duration-300",
              isActive
                ? "text-indigo-600 dark:text-indigo-400"
                : "text-neutral-500 dark:text-neutral-400 hover:text-indigo-600 dark:hover:text-indigo-400"
            ]}
          >
            {item.title}
          </a>
        );
      })
  }
</nav>