
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:responsive_builder/responsive_builder.dart';

import '../constants.dart';
import '../generated/l10n.dart';
import '../store/actions.dart';
import '../store/store.dart';
import '../utils/http_util.dart';
import '../widgets/desktop/desktop_igoshow_learn_more.dart';
import '../widgets/general/bottom_nav.dart';
import '../widgets/general/breadcrumbs.dart';
import '../widgets/general/navigationbar.dart';
import '../widgets/mobile/MobileBottomNav.dart';
import '../widgets/mobile/mobile_igoshow_learn_more.dart';

class IGoShowLearnMore extends StatefulWidget {
  const IGoShowLearnMore({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return IGoShowLearnMoreState();
  }
}

class IGoShowLearnMoreState extends State<IGoShowLearnMore> {
  final _scaffoldKey = GlobalKey<ScaffoldState>();
  Map<String, dynamic> data;

  @override
  Widget build(BuildContext context) {
    store.dispatch(UpdateContext(context));
    if (data == null) {
      return Scaffold(
        body: Center(
          child: SpinKitWave(
            color: Colors.lightBlueAccent,
            size: 40.0,
          ),
        ),
      );
    }

    return ResponsiveBuilder(
      builder: (context, sizingInformation) =>
          Scaffold(
            key: _scaffoldKey,
            appBar: MiniNavigationBar(
              title: S.of(context).igoshow,
              back: true,
              breadCrumbs: [
                BreadCrumb(S.of(context).igoshow, null),
              ],
              breadCrumbHeight: sizingInformation.deviceScreenType == DeviceScreenType.mobile ? null : Constants.BREADCRUMB_HEIGHT,
            ),
            drawer: null,
            body: ScreenTypeLayout(
              mobile: MobileiGoShowLearnMore(data),
              tablet: DesktopiGoShowLearnMore(data),
              desktop: DesktopiGoShowLearnMore(data),
            ),
            bottomNavigationBar: ScreenTypeLayout(
              mobile: MobileBottomNav(currentIndex: 0,),
              tablet: BottomNav(),
              desktop: BottomNav(),
            ),
          ),
    );
  }

  @override
  void initState() {
    super.initState();
    _loadData();
  }

  void _loadData() {
    HttpUtil.httpGet('v1/get-igoshow-learn-more-page')
        .then((value) {
      print('$value');
      if (mounted) {
        setState(() {
          data = value;
        });
      }
    });
  }
}