import 'package:flutter/material.dart';
import 'dart:async';

class AnalyzingDialog extends StatefulWidget {
  const AnalyzingDialog({super.key});

  @override
  State<AnalyzingDialog> createState() => _AnalyzingDialogState();
}

class _AnalyzingDialogState extends State<AnalyzingDialog> {
  int _messageIndex = 0;
  
  final List<String> _messages = [
    'ラベルを読んでいます...',
    '銘柄を確認しています...',
    'この日本酒の個性を分析中...',
    'フレーバーチャートを描画しています...',
    '素敵なキャッチコピーを考えています...',
  ];

  @override
  void initState() {
    super.initState();
    _startMessageRotation();
  }

  void _startMessageRotation() {
    Future.delayed(const Duration(milliseconds: 1500), () {
      if (mounted && _messageIndex < _messages.length - 1) {
        setState(() => _messageIndex++);
        _startMessageRotation();
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Dialog(
      child: Padding(
        padding: const EdgeInsets.all(24.0),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            const CircularProgressIndicator(),
            const SizedBox(height: 24),
            Text(
              _messages[_messageIndex],
              style: Theme.of(context).textTheme.titleMedium,
              textAlign: TextAlign.center,
            ),
          ],
        ),
      ),
    );
  }
}
