import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
import 'package:syncrow_app/navigation/routing_constants.dart';
import 'package:syncrow_app/utils/context_extension.dart';

class LoginUserAgreement extends StatelessWidget {
  const LoginUserAgreement({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<AuthCubit, AuthState>(
      builder: (context, state) {
        return Row(
          children: [
            Checkbox(
              value: AuthCubit.get(context).agreeToTerms,
              onChanged: (value) => AuthCubit.get(context).changeAgreeToTerms(),
            ),
            Expanded(
              child: RichText(
                softWrap: true,
                maxLines: 2,
                text: TextSpan(
                  text: 'I Agree to the ',
                  style: context.bodySmall,
                  children: [
                    TextSpan(
                      text: 'Privacy Policy',
                      style: context.bodySmall.copyWith(
                        color: Colors.blue,
                        decoration: TextDecoration.underline,
                        decorationColor: Colors.blue,
                      ),
                      recognizer: TapGestureRecognizer()
                        ..onTap = () {
                          Navigator.pushNamed(context, Routes.policyRoute);
                        },
                    ),
                    TextSpan(
                      text: ' and ',
                      style: context.bodySmall,
                    ),
                    TextSpan(
                      text: 'User Agreement',
                      recognizer: TapGestureRecognizer()
                        ..onTap = () {
                          Navigator.pushNamed(context, Routes.termsRoute);
                        },
                      style: const TextStyle(
                        color: Colors.blue,
                        decoration: TextDecoration.underline,
                        decorationColor: Colors.blue,
                      ),
                    ),
                    const TextSpan(
                      text: '.',
                      style: TextStyle(
                        color: Colors.black,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        );
      },
    );
  }
}
