import 'package:driverapp/config/config.dart';
import 'package:driverapp/core/viewModels/base_view_model.dart';
import 'package:driverapp/widgets/progress_indicator/app_loader_widget.dart';
import 'package:flutter/material.dart';

import 'arrow_back.dart';
import 'network_base_view.dart';

class AppScaffold extends StatelessWidget {
  final String appBarTitle;
  final Widget body;
  final bool isLoading;
  final bool isShowAppBar;
  final BaseViewModel baseViewModel;
  final Widget bottomSheet;
  final Color titleColor;
  final Color arrowColor;
  final Color appBarColor;

  AppScaffold({
    @required this.body,
    this.appBarTitle = '',
    this.isLoading = false,
    this.isShowAppBar = false,
    this.baseViewModel,
    this.bottomSheet,
    this.titleColor,
    this.arrowColor,
    this.appBarColor,
  });

  @override
  Widget build(BuildContext context) {
    AppGlobal.context = context;
    return SafeArea(
//      top: false,
//      bottom: false,
      child: Scaffold(
        backgroundColor:
            appBarColor ?? Theme.of(context).scaffoldBackgroundColor,
        appBar: isShowAppBar
            ? AppBar(
                elevation: 0,
                backgroundColor: Theme.of(context).appBarTheme.color,
                textTheme: TextTheme(
                  headline6: TextStyle(
                      color: titleColor ?? Colors.white,
                      fontWeight: FontWeight.bold),
                ),
                title: Text(appBarTitle.toUpperCase()),
                leading: Builder(
                  builder: (BuildContext context) {
                    return ArrowBack(
                      arrowColor: arrowColor,
                    );
                  },
                ),
                centerTitle: true,
//                actions: <Widget>[
//                  IconButton(
//                    icon: Icon(FontAwesomeIcons.home),
//                    color: Colors.white,
//                    onPressed: () {
//                      // TODO add navigator to home page
//                    },
//                  ),
//                ],
              )
            : null,
        body: baseViewModel != null
            ? NetworkBaseView(
                child: buildBodyWidget(),
                baseViewModel: baseViewModel,
              )
            : buildBodyWidget(),
        bottomSheet: bottomSheet,
      ),
    );
  }

  buildAppLoaderWidget(bool isLoading) {
    return isLoading ? AppLoaderWidget() : Container();
  }

  buildBodyWidget() {
    return body;
  }
}
