
import 'package:flutter/material.dart';
import 'package:responsive_builder/responsive_builder.dart';

import '../../widgets/desktop/desktop_navigationbar.dart';
import '../../widgets/mobile/mobile_navigationbar.dart';
import 'breadcrumbs.dart';

typedef OnBackPress();

class MiniNavigationBar extends StatefulWidget implements PreferredSizeWidget {
  final Key? key;
  final String title;
  final bool back;
  final bool toHome;
  final bool showMe;
  final List<BreadCrumb>? breadCrumbs;
  final double? breadCrumbHeight;
  final Widget? shoppingCart;

  MiniNavigationBar({Key? key, PreferredSizeWidget? bottom, String? title,
    bool? back, bool? toHome, bool? showMe, this.breadCrumbs,
    this.breadCrumbHeight, this.shoppingCart})
      : key = key,
        preferredSize = breadCrumbHeight != null ? Size.fromHeight(kToolbarHeight + breadCrumbHeight) :
          Size.fromHeight(kToolbarHeight),
        title = title ?? '',
        back = back ?? false,
        toHome = toHome ?? false,
        showMe = showMe ?? true;

  @override
  final Size preferredSize;

  @override
  State<StatefulWidget> createState() {
    return MiniNavigationBarState();
  }

}

class MiniNavigationBarState extends State<MiniNavigationBar> {

  @override
  Widget build(BuildContext context) {
    return ScreenTypeLayout(
      mobile: MobileNavigationBar(title: widget.title, back: widget.back,
        toHome: widget.toHome, showMe: widget.showMe,),
      tablet: DesktopNavigationBar(hasBack: widget.back,
        breadCrumbs: widget.breadCrumbs ?? [], shoppingCart: widget.shoppingCart ?? const SizedBox.shrink(),),
      desktop: DesktopNavigationBar(hasBack: widget.back,
        breadCrumbs: widget.breadCrumbs ?? [], shoppingCart: widget.shoppingCart ?? const SizedBox.shrink(),),
    );
  }

  @override
  void initState() {
    super.initState();
  }
}