import 'package:adaptix/adaptix.dart';
import 'package:flutter/material.dart';
import 'package:sapaly_shop/constants/global_variables.dart';
import 'package:sapaly_shop/themes/app_theme.dart';

void showSnackBar(
  BuildContext ctx, {
  SnackBar Function(String? content)? snackBar,
  String? content,
  Color? textColor,
  Icon? icon,
  Color? backgroundColor,
  Duration? duration,
}) {
  ScaffoldMessenger.of(ctx).hideCurrentSnackBar();

  ScaffoldMessenger.of(ctx).showSnackBar(snackBar == null
      ? SnackBar(
          padding: EdgeInsets.symmetric(
              vertical: 10.adaptedPx(),
              horizontal:
                  7.adaptedPx() + GlobalVariables.horizontalPadding(ctx)),
          duration: duration ?? const Duration(seconds: 2),
          backgroundColor: backgroundColor ?? AppTheme.lightPrimaryColor,
          content: Row(
            children: [
              if (icon != null) icon,
              SizedBox(width: 10.adaptedPx()),
              Text(
                '$content',
                style: TextStyle(
                  fontSize: 15.adaptedPx(),
                  color: textColor ?? Theme.of(ctx).backgroundColor,
                ),
              ),
            ],
          ),
        )
      : snackBar(content));
}

Future<bool> yesOrNoDialog(BuildContext context,
    {String? content, Widget? widgetContent}) async {
  return (await showDialog<bool>(
          context: context,
          builder: (ctx) {
            return AlertDialog(
              title: Text(MaterialLocalizations.of(context).alertDialogLabel),
              titleTextStyle: Theme.of(context).textTheme.bodyLarge?.copyWith(
                  fontFamily: 'Gilroy',
                  fontWeight: FontWeight.w500,
                  fontSize: 17.adaptedPx()),
              titlePadding: EdgeInsets.all(18.adaptedPx()),
              actions: [
                Theme(
                  data: Theme.of(context).copyWith(
                      colorScheme: Theme.of(context).colorScheme.copyWith(
                          primary: Theme.of(context).colorScheme.secondary)),
                  child: TextButton(
                      onPressed: () {
                        Navigator.of(ctx).pop(true);
                      },
                      child: Text(
                        MaterialLocalizations.of(context).continueButtonLabel,
                        style: TextStyle(
                          fontSize: 12.adaptedPx(),
                          fontFamily: 'Gilroy',
                        ),
                      )),
                ),
                Theme(
                  data: Theme.of(context).copyWith(
                      colorScheme: Theme.of(context).colorScheme.copyWith(
                          primary: Theme.of(context).colorScheme.secondary)),
                  child: TextButton(
                      onPressed: () {
                        Navigator.of(ctx).pop(false);
                      },
                      child: Text(
                        MaterialLocalizations.of(context).cancelButtonLabel,
                        style: TextStyle(
                          fontSize: 12.adaptedPx(),
                          fontFamily: 'Gilroy',
                        ),
                      )),
                ),
              ],
              contentTextStyle:
                  Theme.of(context).textTheme.bodyLarge?.copyWith(height: 1.5),
              content: Row(
                children: [
                  if (widgetContent != null)
                    Expanded(child: widgetContent)
                  else
                    Expanded(
                        child: Text(
                      content ?? "",
                      style: Theme.of(context)
                          .primaryTextTheme
                          .bodyText2!
                          .copyWith(
                            fontFamily: 'Gilroy',
                          ),
                    ))
                ],
              ),
            );
          }) ??
      false);
}

class CustomScrollBehavior extends ScrollBehavior {
  @override
  Widget buildOverscrollIndicator(
      BuildContext context, Widget child, ScrollableDetails details) {
    return child;
  }
}
