import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
 * @license
 * Copyright 2025 HopCode Team
 * SPDX-License-Identifier: Apache-2.0
 */
import { useMemo } from 'react';
import { Box } from 'ink';
import { AuthType } from '@hoptrendy/hopcode-core';
import { findProviderByCredentials } from '../../auth/allProviders.js';
import { resolveMetadataKey } from '../../auth/providerConfig.js';
import { Header, AuthDisplayType } from './Header.js';
import { Tips } from './Tips.js';
import { useSettings } from '../contexts/SettingsContext.js';
import { useConfig } from '../contexts/ConfigContext.js';
import { useUIState } from '../contexts/UIStateContext.js';
import { resolveCustomBanner } from '../utils/customBanner.js';
/**
 * Determine the auth display type based on auth type and configuration.
 */
function getAuthDisplayType(authType, baseUrl, apiKeyEnvKey) {
    if (!authType) {
        return AuthDisplayType.UNKNOWN;
    }
    const matched = findProviderByCredentials(baseUrl, apiKeyEnvKey);
    if (matched && resolveMetadataKey(matched)) {
        return matched.label;
    }
    switch (authType) {
        case AuthType.HOPCODE_OAUTH:
            return AuthDisplayType.HOPCODE_OAUTH;
        default:
            return AuthDisplayType.API_KEY;
    }
}
export const AppHeader = ({ version }) => {
    const settings = useSettings();
    const config = useConfig();
    const uiState = useUIState();
    const contentGeneratorConfig = config.getContentGeneratorConfig();
    const authType = contentGeneratorConfig?.authType;
    const model = uiState.currentModel;
    const targetDir = config.getTargetDir();
    const showBanner = !config.getScreenReader() && !settings.merged.ui?.hideBanner;
    const showTips = !(settings.merged.ui?.hideTips || config.getScreenReader());
    const authDisplayType = getAuthDisplayType(authType, contentGeneratorConfig?.baseUrl, contentGeneratorConfig?.apiKeyEnvKey);
    // Resolve once per (settings identity) — file reads and sanitization are
    // not free, and the merged settings reference is stable across renders
    // until a settings hot-reload swaps it.
    const resolvedBanner = useMemo(() => (showBanner ? resolveCustomBanner(settings) : undefined), [showBanner, settings]);
    return (_jsxs(Box, { flexDirection: "column", children: [showBanner && (_jsx(Header, { version: version, authDisplayType: authDisplayType, model: model, workingDirectory: targetDir, customAsciiArt: resolvedBanner?.asciiArt, customBannerTitle: resolvedBanner?.title, customBannerSubtitle: resolvedBanner?.subtitle })), showTips && _jsx(Tips, {})] }));
};
//# sourceMappingURL=AppHeader.js.map