import 'package:didvan/config/theme_data.dart';
import 'package:didvan/constants/app_icons.dart';
import 'package:didvan/models/view/app_bar_data.dart';
import 'package:didvan/views/widgets/didvan/text.dart';
import 'package:flutter/material.dart';

class DidvanAppBar extends StatelessWidget {
  final AppBarData appBarData;
  final bool hasBorder;
  final Color? backgroundColor;
  const DidvanAppBar({
    Key? key,
    required this.appBarData,
    this.hasBorder = false,
    this.backgroundColor = Colors.transparent,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: kToolbarHeight + MediaQuery.of(context).padding.top,
      width: MediaQuery.of(context).size.width,
      padding: const EdgeInsets.only(right: 4, left: 20),
      decoration: BoxDecoration(
        color: backgroundColor,
        border: hasBorder
            ? Border(
                bottom: BorderSide(
                  color: Theme.of(context).colorScheme.cardBorder,
                ),
              )
            : null,
      ),
      child: Row(
        children: [
          IconButton(
            onPressed: () => Navigator.of(context).pop(),
            color: Theme.of(context).colorScheme.title,
            icon: const Icon(
              DidvanIcons.back_regular,
            ),
          ),
          const SizedBox(width: 16),
          Expanded(
            child: Align(
              alignment: Alignment.centerRight,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  if (appBarData.title != null)
                    DidvanText(
                      appBarData.title!,
                      style: Theme.of(context).textTheme.headline3,
                      color: Theme.of(context).colorScheme.title,
                    ),
                  if (appBarData.subtitle != null)
                    DidvanText(
                      appBarData.subtitle!,
                      maxLines: 1,
                      overflow: TextOverflow.clip,
                      style: Theme.of(context).textTheme.overline,
                      color: Theme.of(context).colorScheme.caption,
                    ),
                ],
              ),
            ),
          ),
          if (appBarData.trailing != null) appBarData.trailing!,
        ],
      ),
    );
  }
}
