import 'package:food_health/router/config/route_paths.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

///勾中协议
class AgreementBox extends StatelessWidget {
  final bool checked;
  final Function(bool) onChanged;

  const AgreementBox({
    super.key,
    this.checked = false,
    required this.onChanged,
  });

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        SizedBox(
          width: 25,
          child: Transform.scale(
            scale: 0.8,
            child: Checkbox(
              value: checked,
              shape: CircleBorder(),
              onChanged: (value) {
                onChanged(value!);
              },
            ),
          ),
        ),
        GestureDetector(
          onTap: () {
            onChanged(!checked);
          },
          child: RichText(
            text: TextSpan(
              style: Theme.of(context).textTheme.labelSmall,
              children: [
                TextSpan(
                  text: "I agree to the ",
                ),
                TextSpan(
                  text: "Terms",
                  style: TextStyle(color: Theme.of(context).primaryColor),
                  recognizer: TapGestureRecognizer()
                    ..onTap = () => context.push(
                      RoutePaths.agreement,
                      extra: {"title": "Terms of Service", "url": "https://support.curain.ai/privacy/foodcura/terms_service.html"},
                    ),
                ),
                TextSpan(text: " & "),
                TextSpan(
                  text: "Privacy Policy",
                  style: TextStyle(color: Theme.of(context).primaryColor),
                  recognizer: TapGestureRecognizer()
                    ..onTap = () => context.push(
                      RoutePaths.agreement,
                      extra: {"title": "Privacy", "url": "https://support.curain.ai/privacy/foodcura/privacy_policy.html"},
                    ),
                ),
              ],
            ),
          ),
        ),
      ],
    );
  }
}
