---
interface Props {
    categories: string[];
    activeCategory: string;
    showSearch?: boolean;
}

const { categories, activeCategory, showSearch = true } = Astro.props as Props;
---

<nav class="doc-categories">
    <div class="site-container">
        <div class="categories-inner animate-on-scroll" data-animation="fade-up">
            <div class="categories-list">
                {categories.map((category: string) => (
                    <button
                        class={`category-btn ${category === activeCategory ? 'active' : ''}`}
                        data-category={category}
                    >
                        {category}
                    </button>
                ))}
            </div>

            {showSearch && (
                <button class="search-icon-btn" id="open-search-btn" aria-label="Поиск документов">
                    <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <circle cx="11" cy="11" r="8"></circle>
                        <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
                    </svg>
                </button>
            )}
        </div>
    </div>
</nav>

<style>
    .doc-categories {
        padding: 2rem 0;
        background: rgba(255, 255, 255, 0.02);
    }

    .categories-inner {
        max-width: var(--site-max-width, 1400px);
        margin: 0 auto;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.75rem;
        flex-wrap: wrap;
        padding: 0 1.5rem;
    }

    .categories-list {
        display: contents;
    }

    .category-btn {
        padding: 0.6rem 1.25rem;
        border: 2px solid rgba(255, 255, 255, 0.1);
        border-radius: 2rem;
        background: rgba(255, 255, 255, 0.03);
        color: #94a3b8;
        font-size: 0.875rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        white-space: nowrap;
    }

    .category-btn:hover {
        border-color: rgba(234, 194, 110, 0.3);
        color: #eac26e;
        transform: translateY(-2px);
    }

    .category-btn.active {
        background: linear-gradient(135deg, #eac26e 0%, #ce9f40 100%);
        border-color: #eac26e;
        color: #0f172a;
        box-shadow: 0 4px 12px rgba(234, 194, 110, 0.3);
    }

    .search-icon-btn {
        background: rgba(255, 255, 255, 0.05);
        border: 2px solid rgba(234, 194, 110, 0.3);
        color: #eac26e;
        width: 42px;
        height: 42px;
        border-radius: 2rem;
        cursor: pointer;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    .search-icon-btn:hover {
        background: rgba(234, 194, 110, 0.1);
        border-color: #eac26e;
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(234, 194, 110, 0.3);
    }

    @media (max-width: 768px) {
        .category-btn {
            padding: 0.5rem 1rem;
            font-size: 0.8rem;
        }
    }
</style>

<script>
    function initSearch() {
        const searchBtn = document.getElementById('open-search-btn');
        if (searchBtn) {
            searchBtn.addEventListener('click', () => {
                window.dispatchEvent(new CustomEvent('open-modal', { detail: 'search-modal' }));
            });
        }
    }

    document.addEventListener('DOMContentLoaded', initSearch);
    document.addEventListener('astro:page-load', initSearch);
</script>
