import 'package:flutter/material.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/new_views/pages/land_page/land_page.dart';

import '../app_style/app_color.dart';

class DefaultAppBar extends StatelessWidget implements PreferredSizeWidget {
  final String? title;
  final List<Widget>? actions;
  final Function? onBackPress;
  final bool showHomeActionButton;

  const DefaultAppBar({this.title, this.onBackPress, this.actions, this.showHomeActionButton = false, Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> _actions = [];

    if (showHomeActionButton) {
      _actions.add(
        IconButton(
          icon: const Icon(Icons.home),
          onPressed: () {
            // stopTimer();
            Navigator.pop(context);
            Navigator.popUntil(context, (ModalRoute.withName(LandPage.routeName)));
          },
        ),
      );
    }
    if (actions?.isNotEmpty ?? false) {
      _actions.addAll(actions!);
    }
    return AppBar(
      automaticallyImplyLeading: false,
      titleSpacing: 16,
      title: Row(
        children: [
          const Icon(Icons.arrow_back_ios).onPress(() {
            if (onBackPress != null) {
              onBackPress!();
            } else {
              Navigator.of(context).pop();
            }
          }),
          10.width,
          Text(
            title ?? "",
            style: AppTextStyles.heading3.copyWith(fontWeight: FontWeight.w500, color: context.isDark ? AppColor.neutral30 : AppColor.neutral50),
          ).expanded,
        ],
      ),
      actions: _actions,
    );
  }

  @override
  Size get preferredSize => Size.fromHeight(60.toScreenHeight);
}
