import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
import 'package:doctor_app_flutter/routes.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart';

import '../../widgets/shared/app_loader_widget.dart';
import 'app_texts_widget.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;
  AppScaffold(
      {this.appBarTitle = '',
      this.body,
      this.isLoading = false,
      this.isShowAppBar = true,
      this.baseViewModel, this.bottomSheet});

  @override
  Widget build(BuildContext context) {
    AppGlobal.CONTEX = context;
    ProjectViewModel projectProvider = Provider.of(context);
    return GestureDetector(
      onTap: () {
        FocusScope.of(context).requestFocus(new FocusNode());
      },
      child: Scaffold(
        backgroundColor: Colors.white,
        appBar: isShowAppBar
            ? AppBar(
                elevation: 0,
                backgroundColor: HexColor('#515B5D'),
                textTheme: TextTheme(headline6: TextStyle(color: Colors.white)),
                title: Text(appBarTitle.toUpperCase()),
                leading: Builder(builder: (BuildContext context) {
                  return IconButton(
                    icon: Icon(Icons.arrow_back_ios),
                    color: Colors.white, //Colors.black,
                    onPressed: () => Navigator.pop(context),
                  );
                }),
                centerTitle: true,
                actions: <Widget>[
                  IconButton(
                    icon: Icon(DoctorApp.home_icon_active),
                    color: Colors.white, //Colors.black,
                    onPressed: () => Navigator.pushNamedAndRemoveUntil(
                        context, HOME, (r) => false),
                  ),
                ],
              )
            : null,

        bottomSheet: bottomSheet,
        body: projectProvider.isInternetConnection
            ? baseViewModel != null
                ? NetworkBaseView(
                    baseViewModel: baseViewModel,
                    child: body,
                  )
                : Stack(
                    children: <Widget>[body, buildAppLoaderWidget(isLoading)])
            : Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Image.asset(
                      "assets/images/undraw_connected_world_wuay.png",
                      height: 250,
                    ),
                    AppText('No Internet Connection')
                  ],
                ),
              ),
      ),
    );
  }

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