// ChainEnBadge — small "[EN]" pill shown next to text that came
// from outside Studio's localization pipeline (MCP server tool
// names, n8n endpoint descriptions, native LLM responses).
//
// The honest move: when the active locale isn't English and we
// show a piece of text that we know is English, mark it so the
// operator doesn't blame Studio for a half-translated page.
// `studio.translate` plugin will eventually rewrite these in
// place — until then, the badge is the right amount of
// transparency.

import 'package:flutter/material.dart';

import '../l10n/app_localizations.dart';
import '../theme/tokens.dart';

class ChainEnBadge extends StatelessWidget {
  /// When true, the badge renders. When false (e.g. the active
  /// locale already is English), it returns
  /// `SizedBox.shrink()` so callers can drop it inline without
  /// guarding visibility themselves.
  final bool visible;

  const ChainEnBadge({super.key, required this.visible});

  /// Convenience constructor: derives `visible` from the active
  /// Localizations locale. Use this from inside a Build method
  /// where you already have a BuildContext.
  factory ChainEnBadge.forContext(BuildContext context) {
    final lang = Localizations.localeOf(context).languageCode;
    return ChainEnBadge(visible: lang != 'en');
  }

  @override
  Widget build(BuildContext context) {
    if (!visible) return const SizedBox.shrink();
    final theme = Theme.of(context);
    final l = AppLocalizations.of(context)!;
    return Tooltip(
      message: l.mcpServerEnLanguageBadge,
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
        decoration: BoxDecoration(
          color: theme.colorScheme.surfaceContainerHighest,
          borderRadius: BorderRadius.circular(ChainRadius.sm),
          border: Border.all(color: theme.colorScheme.outlineVariant),
        ),
        child: Text(
          'EN',
          style: theme.textTheme.labelSmall?.copyWith(
            fontSize: 9,
            letterSpacing: 0.4,
            color: theme.colorScheme.onSurfaceVariant,
          ),
        ),
      ),
    );
  }
}
