import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:krow/core/presentation/gen/assets.gen.dart';
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
import 'package:krow/core/presentation/styles/theme.dart';

enum AppBarIconColorStyle { normal, inverted }

class KwAppBar extends AppBar {
  final bool showNotification;
  final Color? contentColor;
  final AppBarIconColorStyle iconColorStyle;

  final String? titleText;

  KwAppBar({
    this.titleText,
    this.showNotification = false,
    this.contentColor,
    bool centerTitle = true,
    this.iconColorStyle = AppBarIconColorStyle.normal,
    super.key,
    super.backgroundColor,
  }) : super(
          leadingWidth: centerTitle ? null : 0,
          elevation: 0,
          centerTitle: centerTitle,
        );

  @override
  List<Widget> get actions {
    return [];//todo remove after implementation
    return [
      if (showNotification)
        Container(
          margin: const EdgeInsets.only(right: 16),
          height: 48,
          width: 48,
          color: Colors.transparent,
          child: Center(
            child: Assets.images.appBar.notification.svg(
                colorFilter: ColorFilter.mode(
                    iconColorStyle == AppBarIconColorStyle.normal
                        ? AppColors.blackBlack
                        : AppColors.grayWhite,
                    BlendMode.srcIn)),
          ),
        ),
    ];
  }

  @override
  Widget? get title {
    return titleText != null
        ? Text(
            titleText!,
            style: _titleTextStyle(contentColor),
          )
        : Assets.images.logo.svg(
            colorFilter: ColorFilter.mode(
                contentColor ?? AppColors.bgColorDark, BlendMode.srcIn));
  }

  @override
  Widget? get leading {
    return Builder(builder: (context) {
      return AutoRouter.of(context).canPop()
          ? GestureDetector(
              onTap: () {
                AutoRouter.of(context).maybePop();
              },
              child: Padding(
                padding: const EdgeInsets.only(left: 20.0),
                child: Container(
                  color: Colors.transparent,
                  height: 40,
                  width: 40,
                  child: Center(
                    child: Assets.images.appBar.appbarLeading.svg(
                      colorFilter: ColorFilter.mode(
                        iconColorStyle == AppBarIconColorStyle.normal
                            ? AppColors.blackBlack
                            : Colors.white,
                        BlendMode.srcIn,
                      ),
                    ),
                  ),
                ),
              ),
            )
          : const SizedBox.shrink();
    });
  }

  static TextStyle _titleTextStyle(contentColor) {
    return AppTextStyles.headingH2.copyWith(
      color: contentColor ?? AppColors.blackBlack,
    );
  }
}
