import 'package:baseproject/core/components/image/custom_image.dart';
import 'package:baseproject/core/language/app_localizations.dart';
import 'package:baseproject/core/theme/custom_color.dart';
import 'package:baseproject/core/theme/size.dart';
import 'package:baseproject/core/theme/text_style.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class ConstantWidget {
  ConstantWidget._internal();

  /// Height
  ///
  /// SizedBox has [height] = 2
  static Widget heightSpace2 = const SizedBox(height: 2);

  /// SizedBox has [height] = 4
  static Widget heightSpace4 = const SizedBox(height: 4);

  /// SizedBox has [height] = 6
  static Widget heightSpace6 = const SizedBox(height: 6);

  /// SizedBox has [height] = 8
  static Widget heightSpace8 = const SizedBox(height: 8);

  /// SizedBox has [height] = 10
  static Widget heightSpace10 = const SizedBox(height: 10);

  /// SizedBox has [height] = 12
  static Widget heightSpace12 = const SizedBox(height: 12);

  /// SizedBox has [height] = 14
  static Widget heightSpace14 = const SizedBox(height: 14);

  /// SizedBox has [height] = 16
  static Widget heightSpace16 = const SizedBox(height: 16);

  /// SizedBox has [height] = 18
  static Widget heightSpace18 = const SizedBox(height: 18);

  /// SizedBox has [height] = 20
  static Widget heightSpace20 = const SizedBox(height: 20);

  /// SizedBox has [height] = 22
  static Widget heightSpace22 = const SizedBox(height: 22);

  /// SizedBox has [height] = 24
  static Widget heightSpace24 = const SizedBox(height: 24);

  /// SizedBox has [height] = 26
  static Widget heightSpace26 = const SizedBox(height: 26);

  /// SizedBox has [height] = 28
  static Widget heightSpace28 = const SizedBox(height: 28);

  /// SizedBox has [height] = 30
  static Widget heightSpace30 = const SizedBox(height: 30);

  /// SizedBox has [height] = 32
  static Widget heightSpace32 = const SizedBox(height: 32);

  /// SizedBox has [height] = 36
  static Widget heightSpace36 = const SizedBox(height: 36);

  /// SizedBox has [height] = 40
  static Widget heightSpace40 = const SizedBox(height: 40);

  /// SizedBox has [height] = 60
  static Widget heightSpace60 = const SizedBox(height: 60);

  /// SizedBox has [height] = 80
  static Widget heightSpace80 = const SizedBox(height: 80);

  /// SizedBox has [height] = 90
  static Widget heightSpace90 = const SizedBox(height: 90);

  /// SizedBox has [height] = 100
  static Widget heightSpace100 = const SizedBox(height: 100);

  /// Width
  ///
  /// SizedBox has [height] = 2
  static Widget widthSpace2 = const SizedBox(width: 2);

  /// SizedBox has [height] = 4
  static Widget widthSpace4 = const SizedBox(width: 4);

  /// SizedBox has [height] = 6
  static Widget widthSpace6 = const SizedBox(width: 6);

  /// SizedBox has [height] = 8
  static Widget widthSpace8 = const SizedBox(width: 8);

  /// SizedBox has [height] = 10
  static Widget widthSpace10 = const SizedBox(width: 10);

  /// SizedBox has [height] = 12
  static Widget widthSpace12 = const SizedBox(width: 12);

  /// SizedBox has [height] = 14
  static Widget widthSpace14 = const SizedBox(width: 14);

  /// SizedBox has [height] = 16
  static Widget widthSpace16 = const SizedBox(width: 16);

  /// SizedBox has [height] = 18
  static Widget widthSpace18 = const SizedBox(width: 18);

  /// SizedBox has [height] = 20
  static Widget widthSpace20 = const SizedBox(width: 20);

  /// SizedBox has [height] = 22
  static Widget widthSpace22 = const SizedBox(width: 22);

  /// SizedBox has [height] = 24
  static Widget widthSpace24 = const SizedBox(width: 24);

  /// SizedBox has [height] = 26
  static Widget widthSpace26 = const SizedBox(width: 26);

  /// SizedBox has [height] = 28
  static Widget widthSpace28 = const SizedBox(width: 28);

  /// SizedBox has [height] = 30
  static Widget widthSpace30 = const SizedBox(width: 30);

  /// SizedBox has [height] = 32
  static Widget widthSpace32 = const SizedBox(width: 32);

  /// SizedBox has [height] = 36
  static Widget widthSpace36 = const SizedBox(width: 36);

  /// SizedBox has [height] = 40
  static Widget widthSpace40 = const SizedBox(width: 40);

  /// SizedBox has [height] = 60
  static Widget widthSpace60 = const SizedBox(width: 60);

  /// SizedBox has [height] = 80
  static Widget widthSpace80 = const SizedBox(width: 80);

  /// SizedBox has [height] = 100
  static Widget widthSpace100 = const SizedBox(width: 100);

  static Widget dividerDefault = Divider(color: CustomColor.dividerDefaultColor, thickness: 1, height: 1);

  static Widget appbarTitleWidget(String text) => Align(
        alignment: Alignment.center,
        child: Text(
          text,
          style: textAppBarDefault,
        ),
      );

  static Widget appBarBackButtonDefault(BuildContext context, {Function()? onBack}) => IconButton(
        padding: EdgeInsets.zero,
        constraints: const BoxConstraints(),
        onPressed: () {
          if (onBack != null) {
            onBack();
          } else {
            Navigator.of(context).pop();
          }
        },
        icon: SizedBox(
          height: 36,
          width: 36,
          child: Icon(
            Icons.arrow_back_ios,
            color: CustomColor.kTextWhiteColor,
            size: 18,
          ),
        ),
      );
  static Widget appBarCloseButtonDefault(BuildContext context) => IconButton(
        padding: EdgeInsets.zero,
        constraints: const BoxConstraints(),
        onPressed: () {
          Navigator.of(context).pop();
        },
        icon: SizedBox(
          height: 36,
          width: 36,
          child: Icon(
            Icons.close,
            color: CustomColor.kTextWhiteColor,
            size: 20,
          ),
        ),
      );

  static Text textBodyDefault(
    String text, {
    FontWeight fontWeight = FontWeight.w400,
    TextDecoration decoration = TextDecoration.none,
    Color? color,
    TextAlign? textAlign,
  }) =>
      Text(
        text,
        style: textStyleBodyDefault.copyWith(
          fontWeight: fontWeight,
          decoration: decoration,
          color: color,
        ),
        textAlign: textAlign,
      );

  static Text textHeadline6(String text) => Text(
        text,
        style: textStyleHeadline6,
      );

  static Text textHeadline6White(String text) => Text(
        text,
        style: textStyleHeadline6.copyWith(color: CustomColor.kTextWhiteColor),
      );

  static Text textBodyDefaultWhite(String text, {FontWeight fontWeight = FontWeight.w400}) => Text(
        text,
        style: textStyleBodyDefault.copyWith(fontWeight: fontWeight, color: CustomColor.kTextWhiteColor),
      );

  static Text textBodySmall(
    String text, {
    FontWeight fontWeight = FontWeight.w400,
    Color? color,
    TextAlign? textAlign,
  }) =>
      Text(
        text,
        style: textStyleBodySmall.copyWith(
          fontWeight: fontWeight,
          color: color,
        ),
        textAlign: textAlign,
      );

  static Text subTextBodySmall(String text, {FontWeight fontWeight = FontWeight.w400}) => Text(
        text,
        style: textStyleBodySmall.copyWith(fontWeight: fontWeight, color: CustomColor.colorSubText),
      );

  static Text textBodySmallWhite(String text, {FontWeight fontWeight = FontWeight.w400}) => Text(
        text,
        style: textStyleBodySmallWhite.copyWith(fontWeight: fontWeight, color: CustomColor.kTextWhiteColor),
      );
  static Card buildCardDefault(
          {required Widget child, EdgeInsets? margin, ShapeBorder? border, EdgeInsets? padding, Color? color}) =>
      Card(
        margin: margin,
        shape: border,
        child: Container(
          color: color,
          width: double.infinity,
          padding: padding ?? const EdgeInsets.all(12),
          child: child,
        ),
      );

  static Container defaultContainer({
    required Widget child,
    double borderRadius = 8,
    Color? color,
    EdgeInsets? padding,
    double? width,
    BoxBorder? border,
  }) =>
      Container(
        width: width,
        child: child,
        padding: padding,
        decoration: BoxDecoration(
          color: color,
          border: border,
          borderRadius: BorderRadius.circular(borderRadius),
        ),
      );

  static Container circleContainer({
    Color? color,
    EdgeInsets? padding,
    required Widget child,
    double? size,
  }) =>
      Container(
        width: size,
        height: size,
        padding: padding,
        decoration: BoxDecoration(
          color: color,
          shape: BoxShape.circle,
        ),
        child: child,
      );

  static Row rowIconAndText(String icPath, String text) => Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          svgImage(icPath, color: CustomColor.colorSubText, width: 18),
          ConstantWidget.widthSpace10,
          Expanded(
            child: Text(
              text,
              style: textStyleBodyDefault,
            ),
          ),
        ],
      );

  static Container titleDateTime(BuildContext context, DateTime date) => titleBackgroundDefault(
        context,
        AppLocalizations.of(context)!.displayDateTime(date, isFullTime: false),
      );

  static Container titleBackgroundDefault(BuildContext context, String text) => Container(
        alignment: Alignment.center,
        width: double.infinity,
        padding: EdgeInsets.symmetric(vertical: 6, horizontal: 2),
        decoration: BoxDecoration(
          color: CustomColor.colorButtonDefault,
          borderRadius: BorderRadius.circular(4),
        ),
        child: Text(
          text,
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
          textAlign: TextAlign.center,
          style: textStyleBodyDefault.copyWith(
            color: CustomColor.colorTextButtonDefault,
            fontWeight: FontWeight.w600,
          ),
        ),
      );

  static Center listLoadingDefault() => const Center(child: CupertinoActivityIndicator());
  static Center noData() => Center(
        child: ConstantWidget.textBodyDefault("Không có dữ liệu"),
      );

  static Container bottomContainer({
    Color? color,
    EdgeInsets? padding,
    required Widget child,
  }) =>
      Container(
        padding: padding ?? paddingBodyDefault.copyWith(top: 10, bottom: 10),
        decoration: BoxDecoration(
          color: CustomColor.kTextWhiteColor,
          boxShadow: [
            BoxShadow(
              color: Colors.grey.withOpacity(0.3),
              spreadRadius: 5,
              blurRadius: 7,
              offset: Offset(0, 3), // changes position of shadow
            ),
          ],
        ),
        child: child,
      );

  static Widget defaultSafeArea({
    bool top = false,
    bool bottom = true,
    required Widget child,
  }) =>
      SafeArea(
        top: top,
        bottom: bottom,
        child: child,
      );

  static ClipRRect defaultTopClipR({required Widget child}) => ClipRRect(
        child: child, //widget.userId Todo
        borderRadius: const BorderRadius.only(
          topLeft: Radius.circular(28),
          topRight: Radius.circular(28),
        ),
      );

  static ElevatedButton buildPrimaryButton({
    VoidCallback? onPressed,
    String text = "",
    EdgeInsets? padding,
    TextStyle? style,
    Widget? child,
    double? textScaleFactor,
  }) =>
      ElevatedButton(
        style: ElevatedButton.styleFrom(
          backgroundColor: CustomColor.bgPriSolid,
          padding: padding,
        ),
        child: child ??
            Text(
              text,
              style: (style ?? textStyleBodyDefaultBold).copyWith(color: CustomColor.kTextWhiteColor),
              textAlign: TextAlign.center,
              textScaleFactor: textScaleFactor,
            ),
        onPressed: onPressed,
      );

  static ElevatedButton buildPrimaryButtonWithIcon(
          {VoidCallback? onPressed,
          required String text,
          required Widget icon,
          EdgeInsets? padding,
          TextStyle? style}) =>
      ElevatedButton(
        style: ElevatedButton.styleFrom(
          backgroundColor: CustomColor.bgPriSolid,
          padding: padding,
        ),
        child: Row(
          children: [
            Expanded(
              child: Text(
                text,
                style: (style ?? textStyleBodyDefaultBold).copyWith(color: CustomColor.kTextWhiteColor),
                textAlign: TextAlign.center,
              ),
            ),
            icon
          ],
        ),
        onPressed: onPressed,
      );

  static ElevatedButton buildSecondButtonWithIcon(
          {VoidCallback? onPressed, required String text, required Widget icon, EdgeInsets? padding}) =>
      ElevatedButton(
        style: ElevatedButton.styleFrom(
          backgroundColor: Color(0xffFDF0E1),
          padding: padding,
        ),
        child: Row(
          children: [
            Expanded(
              child: Text(
                text,
                style: textStyleBodyDefaultBold.copyWith(color: CustomColor.darkSecondColor),
                textAlign: TextAlign.center,
              ),
            ),
            icon
          ],
        ),
        onPressed: onPressed,
      );

  static ElevatedButton buildDefaultButtonWithIcon(
          {VoidCallback? onPressed, required String text, required Widget icon, EdgeInsets? padding}) =>
      ElevatedButton(
        style: ElevatedButton.styleFrom(
          backgroundColor: CustomColor.bgSecondSolid,
          padding: padding,
        ),
        child: Row(
          children: [
            Expanded(
              child: Text(
                text,
                style: textStyleBodyDefaultBold.copyWith(color: CustomColor.kTextWhiteColor),
                textAlign: TextAlign.center,
              ),
            ),
            icon
          ],
        ),
        onPressed: onPressed,
      );
}
