'use client';
import { useState, useEffect } from 'react';
export function useOpenApiTitle() {
    const [title, setTitle] = useState('API Documentation');
    const [loading, setLoading] = useState(true);
    const [error, setError] = useState(null);
    useEffect(()=>{
        async function fetchTitle() {
            try {
                setLoading(true);
                const response = await fetch('/api/openapi-spec');
                if (!response.ok) {
                    throw new Error(`Failed to fetch OpenAPI spec: ${response.status}`);
                }
                const spec = await response.json();
                setTitle(spec.info.title || 'API Documentation');
                setError(null);
            } catch (err) {
                console.error('Error fetching OpenAPI title:', err);
                setError(err instanceof Error ? err.message : 'Unknown error');
                setTitle('API Documentation'); // Fallback title
            } finally{
                setLoading(false);
            }
        }
        fetchTitle();
    }, []);
    return {
        title,
        loading,
        error
    };
}
