import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:lottie/lottie.dart';
import 'package:sigap/src/shared/styles/spacing_styles.dart';
import 'package:sigap/src/utils/constants/colors.dart';
import 'package:sigap/src/utils/constants/sizes.dart';
import 'package:sigap/src/utils/helpers/helper_functions.dart';

class StateScreen extends StatelessWidget {
  const StateScreen({
    super.key,
    required this.title,
    required this.subtitle,
    this.image,
    this.icon,
    this.onPressed,
    this.child,
    this.showButton = false,
    this.secondaryButton = false,
    this.secondaryTitle = 'Continue',
    this.primaryButtonTitle = 'Continue',
    this.onSecondaryPressed,
    this.isLottie = false,
    this.isSvg = false,
  });

  final String? image;
  final IconData? icon;
  final String title, subtitle;
  final String primaryButtonTitle;
  final String secondaryTitle;
  final bool? isLottie;
  final bool isSvg;
  final VoidCallback? onPressed;
  final VoidCallback? onSecondaryPressed;
  final bool showButton;
  final bool secondaryButton;
  final Widget? child;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SingleChildScrollView(
          child: Padding(
            padding: DSpacingStyle.paddingWithAppBarHeight,
            child: Container(
              width: double.infinity,
              constraints: BoxConstraints(
                maxWidth: THelperFunctions.screenWidth() * 0.9,
              ),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  // Image, Icon, Lottie, or SVG
                  if (icon != null)
                    Icon(
                      icon,
                      size: THelperFunctions.screenWidth() * 0.3,
                      color: TColors.primary,
                    )
                  else if (isLottie == true && image != null)
                    Lottie.asset(
                      image!,
                      width: THelperFunctions.screenWidth() * 0.8,
                    )
                  else if (isSvg && image != null)
                    SvgPicture.asset(
                      image!,
                      width: THelperFunctions.screenWidth() * 0.8,
                      colorFilter: const ColorFilter.mode(
                        TColors.primary,
                        BlendMode.srcIn,
                      ),
                    )
                  else if (image != null)
                    Image(
                      image: AssetImage(image!),
                      width: THelperFunctions.screenWidth() * 0.8,
                    ),
                  const SizedBox(height: TSizes.spaceBtwSections),

                  // Title & subtitle
                  Text(
                    title,
                    style: Theme.of(context).textTheme.headlineMedium,
                    textAlign: TextAlign.center,
                  ),
                  const SizedBox(height: TSizes.spaceBtwItems),
                  Text(
                    subtitle,
                    style: Theme.of(context).textTheme.labelMedium,
                    textAlign: TextAlign.center,
                  ),
                  const SizedBox(height: TSizes.spaceBtwSections),

                  // Button
                  if (showButton)
                    SizedBox(
                      width: double.infinity,
                      child: ElevatedButton(
                        onPressed: onPressed,
                        child: Text(primaryButtonTitle),
                      ),
                    ),
                  const SizedBox(height: TSizes.spaceBtwItems),

                  if (secondaryButton)
                    SizedBox(
                      width: double.infinity,
                      child: OutlinedButton(
                        onPressed: onSecondaryPressed,
                        style: ElevatedButton.styleFrom(
                          side: const BorderSide(color: Colors.transparent),
                        ),
                        child: Text(
                          secondaryTitle,
                          style: const TextStyle(color: TColors.primary),
                        ),
                      ),
                    ),

                  // Additional child widget
                  if (child != null) child!,
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
