'use client';

import type { ApiEndpoint, OpenApiInfo, OpenApiSchema } from '../../../types';
import { SchemaCopyMenu } from '../SchemaCopyMenu';

interface BrandHeaderProps {
    info: OpenApiInfo | null;
    /** Used only by ``SchemaCopyMenu`` — displayed label comes from ``info``. */
    endpoints: ApiEndpoint[];
    rawSchema?: OpenApiSchema | null;
    resolvedBaseUrl?: string;
}

/** Topmost row of the sidebar: API title on the left, tiny version
 *  tag below it, and the Copy-for-AI menu on the right. The version
 *  used to sit inline with the title and fought it for space on narrow
 *  panels — stacking them vertically keeps the title at a readable
 *  size and the version as quiet metadata. */
export function BrandHeader({ info, endpoints, rawSchema, resolvedBaseUrl }: BrandHeaderProps) {
    const apiTitle = info?.title ?? 'API Reference';
    const copyReady = rawSchema !== null && rawSchema !== undefined && endpoints.length > 0;

    return (
        <div className="shrink-0 border-b px-3 py-2.5 flex items-start gap-2">
            <div className="flex-1 min-w-0">
                <div
                    className="text-[13px] font-semibold text-foreground leading-tight truncate"
                    title={apiTitle}
                >
                    {apiTitle}
                </div>
                {info?.version && (
                    <div className="font-mono text-[10px] text-muted-foreground/60 leading-tight mt-0.5">
                        v{info.version}
                    </div>
                )}
            </div>
            {copyReady && (
                <SchemaCopyMenu
                    schema={rawSchema ?? null}
                    endpoints={endpoints}
                    baseUrl={resolvedBaseUrl}
                    variant="icon"
                />
            )}
        </div>
    );
}
