import 'package:aitrainer_app/bloc/timer/timer_bloc.dart';
import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/util/common.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:google_fonts/google_fonts.dart';

// ignore: must_be_immutable
class AppBarMin extends StatefulWidget implements PreferredSizeWidget {
  bool back = false;
  AppBarMin({this.back = false});

  @override
  _AppBarNav createState() => _AppBarNav();

  @override
  Size get preferredSize => const Size.fromHeight(50);
}

class _AppBarNav extends State<AppBarMin> with Common {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // ignore: close_sinks
    final TimerBloc timerBloc = BlocProvider.of<TimerBloc>(context);
    return AppBar(
        backgroundColor: Colors.black,
        title: Row(
          mainAxisAlignment: MainAxisAlignment.end,
          children: <Widget>[
            Stack(
              children: [
                Image.asset(
                  'asset/image/WT_long_logo.png',
                  height: 45.0,
                ),
                getTestServer(),
              ],
            ),
          ],
        ),
        leading: IconButton(
          icon: Icon(Icons.arrow_back, color: widget.back ? Colors.white : Colors.black),
          onPressed: () => {
            timerBloc.add(TimerEnd(duration: 0)),
            if (widget.back) {Navigator.of(context).pop()}
          },
        ));
  }

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

  Widget getTestServer() {
    if (Cache().liveServer) {
      return Container();
    } else {
      return Text("TEST",
          style: GoogleFonts.archivoBlack(
            color: Colors.red,
            fontWeight: FontWeight.bold,
            shadows: <Shadow>[
              Shadow(
                offset: Offset(5.0, 5.0),
                blurRadius: 12.0,
                color: Colors.black54,
              ),
              Shadow(
                offset: Offset(-3.0, 3.0),
                blurRadius: 12.0,
                color: Colors.black54,
              ),
            ],
          ));
    }
  }
}
