import 'package:flutter/material.dart';

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

/// 레트로 스타일 선택 다이얼로그
class RetroSelectDialog extends StatelessWidget {
  const RetroSelectDialog({
    super.key,
    required this.title,
    required this.children,
  });

  final String title;
  final List<Widget> children;

  @override
  Widget build(BuildContext context) {
    final background = RetroColors.backgroundOf(context);
    final gold = RetroColors.goldOf(context);

    return Dialog(
      backgroundColor: Colors.transparent,
      child: Container(
        constraints: const BoxConstraints(maxWidth: 320),
        decoration: BoxDecoration(
          color: background,
          border: Border.all(color: gold, width: 2),
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            // 타이틀
            Container(
              width: double.infinity,
              padding: const EdgeInsets.all(12),
              color: gold.withValues(alpha: 0.2),
              child: Text(
                title,
                style: TextStyle(
                  fontFamily: 'PressStart2P',
                  fontSize: 10,
                  color: gold,
                ),
                textAlign: TextAlign.center,
              ),
            ),
            // 옵션 목록
            Padding(
              padding: const EdgeInsets.all(12),
              child: Column(children: children),
            ),
          ],
        ),
      ),
    );
  }
}

/// 선택 옵션 아이템
class RetroOptionItem extends StatelessWidget {
  const RetroOptionItem({
    super.key,
    required this.label,
    required this.isSelected,
    required this.onTap,
    this.prefix,
  });

  final String label;
  final bool isSelected;
  final VoidCallback onTap;
  final String? prefix;

  @override
  Widget build(BuildContext context) {
    final gold = RetroColors.goldOf(context);
    final border = RetroColors.borderOf(context);

    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 4),
      child: GestureDetector(
        onTap: onTap,
        child: Container(
          padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
          decoration: BoxDecoration(
            color: isSelected
                ? gold.withValues(alpha: 0.15)
                : Colors.transparent,
            border: Border.all(
              color: isSelected ? gold : border,
              width: isSelected ? 2 : 1,
            ),
          ),
          child: Row(
            children: [
              if (prefix != null) ...[
                Text(prefix!, style: const TextStyle(fontSize: 16)),
                const SizedBox(width: 12),
              ],
              Expanded(
                child: Text(
                  label,
                  style: TextStyle(
                    fontFamily: 'PressStart2P',
                    fontSize: 18,
                    color: isSelected
                        ? gold
                        : RetroColors.textPrimaryOf(context),
                  ),
                ),
              ),
              if (isSelected) Icon(Icons.check, size: 16, color: gold),
            ],
          ),
        ),
      ),
    );
  }
}
