import 'package:flutter/material.dart';

import 'package:asciineverdie/src/shared/retro_colors.dart';
import 'package:asciineverdie/src/shared/widgets/retro_dialog.dart';

import 'package:asciineverdie/src/features/game/widgets/help/basics_help_view.dart';
import 'package:asciineverdie/src/features/game/widgets/help/combat_help_view.dart';
import 'package:asciineverdie/src/features/game/widgets/help/skills_help_view.dart';
import 'package:asciineverdie/src/features/game/widgets/help/ui_help_view.dart';

/// 도움말 다이얼로그 (Help Dialog)
///
/// 게임 메카닉과 UI 설명을 제공
class HelpDialog extends StatefulWidget {
  const HelpDialog({super.key});

  /// 다이얼로그 표시
  static Future<void> show(BuildContext context) {
    return showDialog(
      context: context,
      barrierColor: Colors.black87,
      builder: (_) => const HelpDialog(),
    );
  }

  @override
  State<HelpDialog> createState() => _HelpDialogState();
}

class _HelpDialogState extends State<HelpDialog>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 4, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final isKorean = Localizations.localeOf(context).languageCode == 'ko';
    final isJapanese = Localizations.localeOf(context).languageCode == 'ja';

    final title = isKorean
        ? '도움말'
        : isJapanese
        ? 'ヘルプ'
        : 'Help';

    final tabs = isKorean
        ? ['기본', '전투', '스킬', 'UI']
        : isJapanese
        ? ['基本', '戦闘', 'スキル', 'UI']
        : ['Basics', 'Combat', 'Skills', 'UI'];

    // 도움말은 MP 블루 색상 사용 (테마 인식)
    final mpColor = RetroColors.mpOf(context);

    return RetroDialog(
      title: title,
      titleIcon: '\u2753',
      accentColor: mpColor,
      child: Column(
        children: [
          // 탭 바 (Tab Bar)
          RetroTabBar(
            controller: _tabController,
            tabs: tabs,
            accentColor: mpColor,
          ),
          // 탭 내용 (Tab Content)
          Expanded(
            child: TabBarView(
              controller: _tabController,
              children: [
                BasicsHelpView(isKorean: isKorean, isJapanese: isJapanese),
                CombatHelpView(isKorean: isKorean, isJapanese: isJapanese),
                SkillsHelpView(isKorean: isKorean, isJapanese: isJapanese),
                UIHelpView(isKorean: isKorean, isJapanese: isJapanese),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
