import 'package:double_back_to_close/double_back_to_close.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hris_selfservice_mobile/Screens/Menu/About/about_screen.dart';
import 'package:hris_selfservice_mobile/Screens/Menu/Absensi/absensi_screen.dart';
import 'package:hris_selfservice_mobile/Screens/Menu/AjukanCuti/ajukancuti_screen.dart';
import 'package:hris_selfservice_mobile/Screens/Menu/Berita/berita_screen.dart';
import 'package:hris_selfservice_mobile/Screens/Menu/Lainnya/lainnya_screen.dart';
import 'package:hris_selfservice_mobile/Screens/Menu/SlipGaji/slipgaji_screen.dart';
import 'package:hris_selfservice_mobile/Screens/Settings/settings_screen.dart';

class HomeView extends StatefulWidget {
  @override
  _HomeView createState() => _HomeView();
}

class _HomeView extends State<HomeView> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DoubleBack(
        onFirstBackPress: (context) {
          final snackBar = SnackBar(content: Text("Double Back Press to Exit"));
          ScaffoldMessenger.of(context).showSnackBar(snackBar);
        },
        message: "Double Back Press to Exit",
        background: Colors.black38,
        backgroundRadius: 10,
        textStyle: TextStyle(
            fontSize: 16, fontWeight: FontWeight.bold, color: Colors.white
        ),
        child: Scaffold(
            resizeToAvoidBottomInset: false,
            //backgroundColor: Colors.white,
            body: Stack(
              children: <Widget>[
                //Background(),
                HomeScreen(),
              ],
            )),
      ),
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var size = MediaQuery
        .of(context)
        .size;
    return Scaffold(
        body: SingleChildScrollView(
          child: Stack(
            children: <Widget>[
              Container(
                height: size.height * 0.3,
                decoration: BoxDecoration(
                    gradient: LinearGradient(
                        begin: Alignment.topRight,
                        end: Alignment.bottomRight,
                        colors: [
                          Color(0xFFD21404),
                          Color(0xFFFD7267),
                        ])),
              ),
              SafeArea(
                child: Padding(
                  padding: EdgeInsets.all(20),
                  child: Column(
                    children: <Widget>[
                      Align(
                        alignment: Alignment.topRight,
                        child: InkWell(
                          child: Container(
                              alignment: Alignment.center,
                              height: 40,
                              width: 40,
                              child: Image.asset(
                                  'assets/images/ic_settings.png')),
                          onTap: () {
                            Navigator.push(
                                context,
                                MaterialPageRoute(
                                    builder: (context) =>
                                        SettingsScreen()));
                          },
                        ),
                      ),
                      Stack(
                        alignment: Alignment.topCenter,
                        children: [
                          Container(
                            margin: EdgeInsets.only(top: ((size.width - 20) *
                                0.3) * 0.5),
                            child: Card(
                              elevation: 15,
                              child: Container(
                                  height: size.width * 0.35,
                                  width: size.width - 20,
                                  padding: EdgeInsets.all(15),
                                  decoration: BoxDecoration(
                                      color: Colors.white,
                                      borderRadius:
                                      BorderRadius.all(Radius.circular(10))),
                                  child: Column(
                                    mainAxisAlignment: MainAxisAlignment.end,
                                    crossAxisAlignment: CrossAxisAlignment
                                        .center,
                                    children: <Widget>[
                                      Text(
                                        'Dieni Anindyasarathi',
                                        maxLines: 2,
                                        overflow: TextOverflow.ellipsis,
                                        textAlign: TextAlign.center,
                                        style: GoogleFonts.inter(
                                            fontSize: 17,
                                            color: Colors.black,
                                            fontWeight: FontWeight.bold),
                                      ),
                                      Text(
                                        'IT Developer',
                                        textAlign: TextAlign.center,
                                        style: GoogleFonts.inter(
                                            fontSize: 16, color: Colors.black),
                                      ),
                                    ],
                                  )),
                            ),
                          ),
                          Container(
                            alignment: Alignment.topCenter,
                            height: (size.width - 20) * 0.3,
                            width: (size.width - 20) * 0.3,
                            decoration: BoxDecoration(
                              color: Colors.black,
                              image: DecorationImage(
                                image: AssetImage(
                                    'assets/images/ic_administrator.png'),
                                fit: BoxFit.fill,
                              ),
                              shape: BoxShape.circle,
                            ),
                          ),
                        ],
                      ),
                      GridView.count(
                        shrinkWrap: true,
                        physics: NeverScrollableScrollPhysics(),
                        padding: EdgeInsets.only(top: 25, left: 5, right: 5),
                        crossAxisSpacing: 15,
                        mainAxisSpacing: 15,
                        crossAxisCount: 2,
                        children: <Widget>[
                          InkWell(
                            child: Container(
                              decoration: BoxDecoration(
                                  color: Color(0xFFD9D9D9),
                                  borderRadius: BorderRadius.circular(5)),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: <Widget>[
                                  Image.asset(
                                    "assets/icons/menu/ic_menu_absensi2.png",
                                    width: 75,
                                    height: 75,
                                  ),
                                  Text(
                                    'Absensi',
                                    textAlign: TextAlign.center,
                                    style: GoogleFonts.acme(
                                        fontSize: 18, color: Colors.black),
                                  )
                                ],
                              ),
                            ),
                            onTap:(){
                              Navigator.push(context, MaterialPageRoute(
                                  builder: (context) => AbsensiScreen()));
                            }
                          ),
                          InkWell(
                            child: Container(
                              decoration: BoxDecoration(
                                  color: Color(0xFFD9D9D9),
                                  borderRadius: BorderRadius.circular(5)),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: <Widget>[
                                  Image.asset(
                                      "assets/icons/menu/ic_menu_slipgaji2.png",
                                      height: 75,
                                      width: 75),
                                  Text(
                                    'Slip Gaji',
                                    textAlign: TextAlign.center,
                                    style: GoogleFonts.acme(
                                        fontSize: 18, color: Colors.black),
                                  )
                                ],
                              ),
                            ),
                            onTap: (){
                              Navigator.push(context, MaterialPageRoute(
                                  builder: (context) => SlipGajiScreen()));
                            },
                          ),
                          InkWell(
                            child: Container(
                              decoration: BoxDecoration(
                                  color: Color(0xFFD9D9D9),
                                  borderRadius: BorderRadius.circular(5)),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: <Widget>[
                                  Image.asset(
                                      "assets/icons/menu/ic_menu_ajukancuti2.png",
                                      height: 75,
                                      width: 75),
                                  Text(
                                    'Ajukan Cuti',
                                    textAlign: TextAlign.center,
                                    style: GoogleFonts.acme(
                                        fontSize: 18, color: Colors.black),
                                  )
                                ],
                              ),
                            ),
                            onTap: (){
                              Navigator.push(context, MaterialPageRoute(
                                  builder: (context) => AjukanCutiScreen()));
                            },
                          ),
                          InkWell(
                            child: Container(
                              decoration: BoxDecoration(
                                  color: Color(0xFFD9D9D9),
                                  borderRadius: BorderRadius.circular(5)),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: <Widget>[
                                  Image.asset(
                                      "assets/icons/menu/ic_menu_berita2.png",
                                      height: 75, width: 75),
                                  Text(
                                    'Berita',
                                    textAlign: TextAlign.center,
                                    style: GoogleFonts.acme(
                                        fontSize: 18, color: Colors.black),
                                  )
                                ],
                              ),
                            ),
                            onTap: (){
                              Navigator.push(context, MaterialPageRoute(
                                  builder: (context) => BeritaScreen()));
                            },
                          ),
                          InkWell(
                            child: Container(
                              decoration: BoxDecoration(
                                  color: Color(0xFFD9D9D9),
                                  borderRadius: BorderRadius.circular(5)),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: <Widget>[
                                  Image.asset(
                                      "assets/icons/menu/ic_menu_about2.png",
                                      height: 75, width: 75),
                                  Text(
                                    'About',
                                    textAlign: TextAlign.center,
                                    style: GoogleFonts.acme(
                                        fontSize: 18, color: Colors.black),
                                  )
                                ],
                              ),
                            ),
                            onTap: (){
                              Navigator.push(context, MaterialPageRoute(
                                  builder: (context) => AboutScreen()));
                            },
                          ),
                          InkWell(
                            child: Container(
                              decoration: BoxDecoration(
                                  color: Color(0xFFD9D9D9),
                                  borderRadius: BorderRadius.circular(5)),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: <Widget>[
                                  Image.asset(
                                      "assets/icons/menu/ic_menu_lainnya.png",
                                      height: 75, width: 75),
                                  Text(
                                    'Lainnya',
                                    textAlign: TextAlign.center,
                                    style: GoogleFonts.acme(
                                        fontSize: 18, color: Colors.black),
                                  )
                                ],
                              ),
                            ),
                            onTap: (){
                              Navigator.push(context, MaterialPageRoute(
                                  builder: (context) => LainnyaScreen()));
                            },
                          ),
                        ],
                      )
                    ],
                  ),
                ),
              ),
            ],
          ),
        ));
  }
}