import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/providers/project_provider.dart';
import 'package:doctor_app_flutter/routes.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart';
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
import '../../widgets/shared/app_loader_widget.dart';
import 'app_texts_widget.dart';

class AppScaffold extends StatelessWidget {
  String appBarTitle;
  Widget body;
  bool isLoading;
  bool isShowAppBar;

  AppScaffold(
      {this.appBarTitle = '',
      this.body,
      this.isLoading = false,
      this.isShowAppBar = true});

  @override
  Widget build(BuildContext context) {
    AppGlobal.CONTEX = context;
    ProjectProvider projectProvider = Provider.of(context);
    return Scaffold(
        backgroundColor: Hexcolor('#F5F5F5'),
        appBar: isShowAppBar
            ? AppBar(
                elevation: 0,
                backgroundColor: Hexcolor('#515B5D'),
                textTheme: TextTheme(
                    headline6: TextStyle(
                        color: Colors.white, fontWeight: FontWeight.bold)),
                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,
        body: projectProvider.isInternetConnection
            ? 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();
  }
}
