import 'dart:ui';
import 'package:rate_my_app/rate_my_app.dart';
import 'package:road24_mobile/view/base/splash/splash_screen.dart';
import 'package:sizer/sizer.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:road24_mobile/model/utils/styles/AppStyles.dart';
import 'package:road24_mobile/view/built/i18n.dart';
import 'package:road24_mobile/view/widgets/custom_button.dart';

class SuccessPage extends StatelessWidget {
  final Function()? onTap;
  final Function()? onTapSkip;
  final String text;
  final String? subText;
  final bool? fromFinePaying;

  const SuccessPage({
    Key? key,
    required this.onTap,
    required this.text,
    this.subText,
    this.onTapSkip,
    this.fromFinePaying,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    print(onTapSkip);
    return RateMyAppBuilder(
      rateMyApp: SplashScreen.rateMyApp,
      onInitialized: (context, rateMyApp) {
        try {
          rateMyApp.conditions.forEach((condition) {
            if (condition is DebuggableCondition) {
              print(condition
                  .valuesAsString); // We iterate through our list of conditions and we print all debuggable ones.
            }
          });
          print('Are all conditions met ? ' +
              (rateMyApp.shouldOpenDialog ? 'Yes' : 'No'));
          if (rateMyApp.shouldOpenDialog && fromFinePaying == true) {
            rateMyApp.showRateDialog(context,
                title: S.of(context).rate_title,
                message: S.of(context).rate_message,
                rateButton: S.of(context).rate_button,
                noButton: S.of(context).rate_no_button,
                laterButton: S.of(context).rate_later_button,
                dialogStyle: DialogStyle(
                  titleStyle: AppStyle.textStyle().copyWith(
                    color: Color(0xff282828),
                    fontSize: 18.0,
                    fontWeight: FontWeight.w600,
                  ),
                  messageStyle: AppStyle.textStyle().copyWith(
                    color: Color(0xff282828),
                    fontSize: 16.0,
                    fontWeight: FontWeight.w400,
                  ),
                ));
          }
        } catch (e) {
          print("rate ex.....$e");
        }
      },
      builder: (context) => Scaffold(
        backgroundColor: Color(0xffF9F9F9),
        body: ListView(
          shrinkWrap: true,
          children: [
            SizedBox(height: 20.0.h),
            SizedBox(height: kToolbarHeight),
            Row(
              children: [Image.asset("assets/png/thumb_up_success.png")],
            ),
            SizedBox(height: 5.0.h),
            Padding(
              padding: EdgeInsets.symmetric(horizontal: 5.0.w),
              child: Text(
                text,
                style: AppStyle.textStyle().copyWith(
                  color: Color(0xff282828),
                  fontSize: 24.0,
                  fontWeight: FontWeight.bold,
                ),
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
              ),
            ),
            SizedBox(height: 2.0.w),
            if (subText != null)
              Padding(
                padding: EdgeInsets.symmetric(horizontal: 5.0.w),
                child: Text(
                  subText!,
                  style: AppStyle.textStyle().copyWith(
                      color: Color(0xff747474),
                      fontWeight: FontWeight.normal,
                      fontSize: 15.0),
                ),
              ),
            if (subText != null) SizedBox(height: 2.0.w),
            Padding(
              padding: EdgeInsets.symmetric(horizontal: 5.0.w),
              child: CustomButton(
                color: Color(0xffDCDCDC),
                onTap: onTap,
                title: "${S.of(context).ok}",
                textStyle: AppStyle.textStyle().copyWith(
                    color: Color(0xff333333),
                    fontWeight: FontWeight.w600,
                    fontSize: 19.0),
              ),
            ),
            if (onTapSkip != null) SizedBox(height: 2.0.w),
            if (onTapSkip != null)
              Padding(
                padding: EdgeInsets.symmetric(horizontal: 5.0.w),
                child: Container(
                  height: 14.0.w,
                  child: TextButton(
                    style: TextButton.styleFrom(
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(12.0),
                      ),
                    ),
                    onPressed: onTapSkip,
                    child: Text(
                      S.of(context).skip,
                      style: AppStyle.textStyle()
                          .copyWith(color: Colors.black, fontSize: 17.0),
                    ),
                  ),
                ),
              ),
            SizedBox(height: 5.0.w),
          ],
        ),
      ),
    );
  }
}
