import 'package:bookmywages/consts_widgets/app_assets.dart';
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/consts_widgets/comman_button.dart';
import 'package:bookmywages/routers/consts_router.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';

class WelcomePage extends StatefulWidget {
  const WelcomePage({super.key});

  @override
  State<WelcomePage> createState() => _WelcomePageState();
}

class _WelcomePageState extends State<WelcomePage> {
  @override
  Widget build(BuildContext context) {
    final Size screenSize = MediaQuery.of(context).size;
    final double textScale = MediaQuery.of(context).textScaleFactor;

    final bool isMobile = screenSize.width < 600;
    final bool isTablet = screenSize.width >= 600 && screenSize.width < 1200;
    final bool isDesktop = screenSize.width >= 1200;

    final double headingFontSize =
        (isMobile ? 25 : (isTablet ? 28 : 32)) * textScale;
    final double buttonFontSize =
        (isMobile ? 18 : (isTablet ? 22 : 25)) * textScale;
    final double horizontalPadding = screenSize.width * 0.05;
    final double topPadding = screenSize.height * 0.05;
    final double verticalSpacing = screenSize.height * 0.03;

    return Scaffold(
      backgroundColor: AppColors.secondprimary,
      body: SafeArea(
        child: SingleChildScrollView(
          child: Center(
            child: ConstrainedBox(
              constraints: const BoxConstraints(maxWidth: 800),
              child: Padding(
                padding: EdgeInsets.symmetric(
                  horizontal: horizontalPadding.clamp(16.0, 32.0),
                  vertical: topPadding,
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    ConstrainedBox(
                      constraints: BoxConstraints(maxWidth: 250),
                      child: RichText(
                        textAlign: TextAlign.start,
                        text: TextSpan(
                          style: TextStyle(
                            fontFamily: 'Gilroy',
                            fontWeight: FontWeight.w900,
                            fontSize: headingFontSize,
                            height: 1.65,
                            letterSpacing: headingFontSize * 0.01,
                          ),
                          children: const [
                            TextSpan(
                              text: "Explore The All Types Of ",
                              style: TextStyle(color: AppColors.thridprimary),
                            ),
                            TextSpan(
                              text: "Service",
                              style: TextStyle(color: Color(0xFF3A47C9)),
                            ),
                          ],
                        ),
                      ),
                    ),
                    SizedBox(height: verticalSpacing),
                    Center(
                      child: ConstrainedBox(
                        constraints: BoxConstraints(
                          maxWidth: isDesktop
                              ? screenSize.width * 0.5
                              : (isTablet
                                    ? screenSize.width * 0.7
                                    : screenSize.width * 0.85),
                        ),
                        child: Image.asset(
                          AppAssets.welcome,
                          fit: BoxFit.contain,
                        ),
                      ),
                    ),
                    SizedBox(height: verticalSpacing * 1.6),
                    Center(
                      child: ConstrainedBox(
                        constraints: BoxConstraints(
                          maxWidth: isDesktop
                              ? screenSize.width * 0.3
                              : (isTablet
                                    ? screenSize.width * 0.5
                                    : screenSize.width * 0.85),
                        ),
                        child: CommanButton(
                          text: 'Sign in',
                          textStyle: TextStyle(
                            fontFamily: 'Gilroy-Black',
                            fontWeight: FontWeight.w800,
                            fontSize: buttonFontSize,
                            height: 1.0,
                            letterSpacing: buttonFontSize * 0.02,
                            color: AppColors.secondprimary,
                          ),

                          onPressed: () => Get.toNamed(RouterConts.loginpage),
                          isPrimary: true,
                          backgroundColor: AppColors.primary,
                          textColor: AppColors.secondprimary,
                        ),
                      ),
                    ),
                    SizedBox(height: verticalSpacing),
                    Center(
                      child: ConstrainedBox(
                        constraints: BoxConstraints(
                          maxWidth: isDesktop
                              ? screenSize.width * 0.3
                              : (isTablet
                                    ? screenSize.width * 0.5
                                    : screenSize.width * 0.85),
                        ),
                        child: CommanButton(
                          text: 'Sign up',
                          textStyle: TextStyle(
                            fontFamily: 'Gilroy-Black',
                            fontWeight: FontWeight.w800,
                            fontSize: buttonFontSize,
                            height: 1.0,
                            letterSpacing: buttonFontSize * 0.02,
                            color: AppColors.hittext,
                          ),

                          onPressed: () => Get.toNamed(RouterConts.siguppage),
                          isPrimary: false,
                        ),
                      ),
                    ),
                    SizedBox(height: verticalSpacing),
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
