import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show FilteringTextInputFormatter;

import 'package:asciineverdie/l10n/app_localizations.dart';
import 'package:asciineverdie/src/shared/retro_colors.dart';
import 'package:asciineverdie/src/shared/widgets/retro_widgets.dart';

/// 캐릭터 이름 입력 섹션
class NameInputSection extends StatelessWidget {
  const NameInputSection({
    super.key,
    required this.controller,
    required this.onGenerateName,
  });

  final TextEditingController controller;
  final VoidCallback onGenerateName;

  @override
  Widget build(BuildContext context) {
    final l10n = L10n.of(context);
    return RetroPanel(
      title: l10n.nameTitle,
      child: Row(
        children: [
          Expanded(
            child: TextField(
              controller: controller,
              style: const TextStyle(
                fontFamily: 'PressStart2P',
                fontSize: 14,
                color: RetroColors.textLight,
              ),
              // 영문 알파벳만 허용 (공백 불가)
              inputFormatters: [
                FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z]')),
              ],
              decoration: InputDecoration(
                labelText: l10n.name,
                labelStyle: const TextStyle(
                  fontFamily: 'PressStart2P',
                  fontSize: 13,
                  color: RetroColors.gold,
                ),
                border: const OutlineInputBorder(
                  borderSide: BorderSide(color: RetroColors.panelBorderInner),
                ),
                enabledBorder: const OutlineInputBorder(
                  borderSide: BorderSide(color: RetroColors.panelBorderInner),
                ),
                focusedBorder: const OutlineInputBorder(
                  borderSide: BorderSide(color: RetroColors.gold, width: 2),
                ),
                counterStyle: const TextStyle(color: RetroColors.textDisabled),
              ),
              maxLength: 30,
            ),
          ),
          const SizedBox(width: 8),
          RetroIconButton(icon: Icons.casino, onPressed: onGenerateName),
        ],
      ),
    );
  }
}
