<script setup lang="ts">
import { apiFetch } from '~/utils/apiFetch';

const { data: menuData } = await apiFetch<ApiMenuType>(`menu/1/`)
const pagesData = (menuData.value ? menuData.value.pages : []).sort((a, b) => a.order - b.order)
const route = useRoute()
</script>
<template>
    <div class="header">
        <div class="container">
            <div class="logo">
                <NuxtLink to="/">
                    Купи забор
                </NuxtLink>
            </div>
            <div class="menu">
                <template v-for="item in pagesData">
                    <NuxtLink :to="item.external_link || ((route.name == 'index' ? '' : '/') + `#${item.slug}`)"
                        :target="item.external_link ? '_blank' : '_self'">
                        {{ item.menu_title }}
                    </NuxtLink>
                </template>
            </div>
        </div>
    </div>
</template>
