import 'package:adaptix/adaptix.dart';
import 'package:flutter/material.dart';
import 'package:sapaly_shop/features/widgets/sapaly_icon.dart';

import '../../themes/app_theme.dart';

class SapalyAppBar extends StatelessWidget with PreferredSizeWidget {
  const SapalyAppBar({
    Key? key,
    required this.hasActionButton,
    required this.title,
    required this.actionButton,
    required this.leadingButton,
    required this.leadingOnTap,
    required this.actionOnTap,
    required this.badge,
  }) : super(key: key);

  final bool hasActionButton;
  final String title, badge;
  final Widget leadingButton;
  final void Function() leadingOnTap;
  final void Function() actionOnTap;
  final Widget actionButton;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(10.adaptedPx()),
      child: AppBar(
        backgroundColor: AppTheme.lightBackgroundColor,
        toolbarHeight: 65.adaptedPx(),
        centerTitle: true,
        elevation: 0,
        titleTextStyle: Theme.of(context).primaryTextTheme.bodyMedium?.copyWith(
              color: AppTheme.blackColor,
              fontWeight: FontWeight.w600,
              fontSize: 17.adaptedPx(),
            ),
        toolbarTextStyle:
            Theme.of(context).primaryTextTheme.bodyMedium?.copyWith(
                  color: AppTheme.blackColor,
                  fontWeight: FontWeight.w600,
                  fontSize: 20.adaptedPx(),
                ),
        leading: SapalyIcon(
          height: 50.adaptedPx(),
          width: 50.adaptedPx(),
          onTap: leadingOnTap,
          hasBadge: false,
          child: leadingButton,
        ),
        title: Text(
          title,
        ),
        actions: [
          hasActionButton
              ? SapalyIcon(
                  onTap: actionOnTap,
                  height: 50.adaptedPx(),
                  width: 50.adaptedPx(),
                  hasBadge: true,
                  badge: badge,
                  child: actionButton,
                )
              : Container(),
        ],
        // ],
      ),
    );
  }

  @override
  Size get preferredSize => Size(0, 75.adaptedPx());
}
