import 'package:flutter/material.dart';

class UpgradeDialog extends StatelessWidget {
  final String version;
  final List<String> content;

  final bool force;
  final VoidCallback onConfirm;

  const UpgradeDialog({
    super.key,
    required this.version,
    required this.content,
    required this.force,
    required this.onConfirm,
  });

  @override
  Widget build(BuildContext context) {
    return PopScope(
      canPop: !force, // 强制更新时不能返回，非强制更新时可以返回
      child: Dialog(
        insetPadding: EdgeInsets.all(30),
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
        child: Padding(
          padding: const EdgeInsets.all(20),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Image.asset('assets/images/update/rocket.png', width: 80, height: 80),
              const SizedBox(height: 12),
              Text("发现新版本 $version", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
              const SizedBox(height: 10),
              // Text(content, style: TextStyle(fontSize: 14)),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                // children: content.map((line) => Text("• $line")).toList(),
                children: content.asMap().entries.map((entry) {
                  final index = entry.key;
                  final line = entry.value;
                  return Text("${index + 1}. $line");
                }).toList(),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                onPressed: onConfirm,
                child: Text("立即更新"),
              ),
              if (!force)
                TextButton(
                  onPressed: () => Navigator.pop(context),
                  child: Text("暂不更新"),
                )
            ],
          ),
        ),
      ),
    );
  }
}
