import 'package:eitc_erm_dental_flutter/exts.dart';
import 'package:eitc_erm_dental_flutter/funcs.dart';
import 'package:eitc_erm_dental_flutter/widget/main_button.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

///APP启动提示弹窗
class AppStartAgreementDialog extends StatelessWidget {
  const AppStartAgreementDialog({super.key});

  @override
  Widget build(BuildContext context) {
    return PopScope(
        canPop: false,
        child: Dialog(
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.r)),
          child: Padding(
            padding: EdgeInsets.all(20.r),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Text(
                  getS().permissionDescDialogTitle,
                  textAlign: TextAlign.center,
                  style: context.titleMedium,
                ),
                SizedBox(
                  height: 20.h,
                ),
                Text(getS().permissionDescDialogContent(appName)),
                SizedBox(
                  height: 10.h,
                ),
                Text.rich(
                    softWrap: true,
                    TextSpan(text: "${getS().read} ", children: [
                      _getClickTextSpan(context, getS().userAgreementBookTitle,
                          () => gotoUserAgreement(context, checkWifi: false)),
                      TextSpan(text: "、"),
                      _getClickTextSpan(context, getS().privacyPolicyBookTitle,
                          () => gotoPrivacyPolicy(context, checkWifi: false)),
                      TextSpan(text: "、"),
                      _getClickTextSpan(
                          context,
                          getS().permissionDescriptionBookTitle,
                          () => gotoPermissionDesc(context, checkWifi: false)),
                    ])),
                SizedBox(
                  height: 15.h,
                ),
                Row(
                  children: [
                    Expanded(
                        child: MainButton(
                      text: getS().exitApp,
                      onPressed: () => Navigator.of(context).pop(false),
                      buttonPadding: EdgeInsets.zero,
                      isOutlined: true,
                    )),
                    SizedBox(
                      width: 10.w,
                    ),
                    Expanded(
                        child: MainButton(
                            text: getS().agreeContinue,
                            buttonPadding: EdgeInsets.zero,
                            onPressed: () => Navigator.of(context).pop(true)))
                  ],
                )
              ],
            ),
          ),
        ));
  }

  TextSpan _getClickTextSpan(
      BuildContext context, String text, GestureTapCallback onTap) {
    return TextSpan(
        text: text,
        style: TextStyle(color: context.primaryColor),
        recognizer: TapGestureRecognizer()..onTap = onTap);
  }
}
