import 'dart:math';

import 'package:auto_route/auto_route.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class Header extends StatelessWidget {
  final String? title;
  final String? subtitle;

  final bool hasPopButton;
  final String? popText;
  final Widget? trail;
  final Color? color;

  Header(
    this.title, {
    this.subtitle,
    this.hasPopButton = false,
    this.popText,
    this.trail,
    this.color,
  });

  @override
  Widget build(BuildContext context) {
    final topPadding = 74.h -
        MediaQuery.of(context).padding.top -
        (hasPopButton ? 30.0.h : 0.0);
    return Container(
      color: color,
      alignment: Alignment.centerLeft,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SizedBox(
            height: max(
              topPadding / 2,
              0,
            ),
          ),
          if (hasPopButton)
            Padding(
              padding: EdgeInsets.only(left: 10.0.w),
              child: TapRegion(
                onTapInside: AutoRouter.of(context).maybePop,
                behavior: HitTestBehavior.opaque,
                child: SizedBox(
                  height: 30.h,
                  child: Row(
                    children: [
                      Image.asset(
                        'icons/back.png',
                        color: Colors.black,
                        width: 17,
                        height: 23.h,
                      ),
                      if (popText != null)
                        Padding(
                          padding: const EdgeInsets.only(left: 4.0),
                          child: Text(
                            popText!,
                            style: TextStyle(
                              fontSize: 16,
                              fontWeight: FontWeight.w400,
                            ),
                          ),
                        ),
                    ],
                  ),
                ),
              ),
            ),
          SizedBox(
            height: max(
              topPadding / 2,
              0,
            ),
          ),
          Container(
            padding: EdgeInsets.only(left: 20.0.w, right: 24.w),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                if (title != null)
                  Text(
                    title!,
                    style: TextStyle(
                      fontSize: 36.sp,
                      fontWeight: FontWeight.w500,
                      height: 0.85,
                    ),
                    textAlign: TextAlign.start,
                  ),
                if (trail != null) trail!,
              ],
            ),
          ),
          if (subtitle != null)
            Container(
              padding: EdgeInsets.only(top: 4.0.h, left: 22.0.w, bottom: 4.0.h),
              alignment: Alignment.centerLeft,
              child: Text(
                subtitle!,
                style: TextStyle(
                  fontSize: 20.sp,
                  fontWeight: FontWeight.w300,
                  height: 0.85,
                ),
              ),
            ),
        ],
      ),
    );
  }
}
