import 'package:fis_i18n/i18n.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:percent_indicator/circular_percent_indicator.dart';

class ProgressCircle extends StatelessWidget {
  final double progress; // 进度百分比，范围：0.0 到 1.0
  final double diameter; // 圆形进度指示器的直径
  final void Function()? onCancel;
  final String? hintText;
  ProgressCircle({
    Key? key,
    required this.progress,
    this.diameter = 100.0, // 默认值为100.0
    this.onCancel,
    this.hintText,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        CircularPercentIndicator(
          radius: diameter,
          lineWidth: 10.0,
          progressColor: Colors.blue,
          backgroundColor: Colors.grey,
          circularStrokeCap: CircularStrokeCap.round,
          center: FColumn(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              if (hintText != null) ...[
                FText(
                  hintText!,
                  style: TextStyle(
                    fontSize: 16.0,
                    color: Colors.white,
                  ),
                ),
              ],
              FText(
                '${(progress * 100).toStringAsFixed(0)}%',
                style: TextStyle(
                    fontSize: 18.0,
                    fontWeight: FontWeight.bold,
                    color: Colors.white),
              ),
            ],
          ),
          percent: progress,
        ),
        FTextButton(
          businessParent: FVirtualPageWidget("cancel process"),
          name: 'cancel',
          onPressed: () {
            onCancel?.call();
          },
          child: FText(
            i18nBook.common.cancel.t,
            style: TextStyle(color: Colors.white),
          ),
        ),
      ],
    );
  }
}
