
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:flutter_wisetronic/utils/http_util.dart';
import 'package:flutter_wisetronic/utils/utils.dart';
import 'package:flutter_wisetronic/widgets/desktop/desktop_renew_minioffice.dart';
import 'package:flutter_wisetronic/widgets/mobile/mobile_renew_minioffice.dart';
import 'package:responsive_builder/responsive_builder.dart';

import '../constants.dart';
import '../models/business.dart';
import '../store/actions.dart';
import '../store/store.dart';
import '../widgets/desktop/desktop_renew_license.dart';
import '../widgets/mobile/mobile_renew_license.dart';

class RenewMiniOffice extends StatefulWidget {
  final int gid;

  const RenewMiniOffice(this.gid, {Key? key}) :
      super(key: key);

  @override
  State<StatefulWidget> createState() => RenewMiniOfficeState();
}

class RenewMiniOfficeState extends State<RenewMiniOffice> {
  Map<String, dynamic> data;

  @override
  Widget build(BuildContext context) {

    store.dispatch(UpdateContext(context));

    if (data == null ) {
      return new Scaffold(
        body: Center(
          child: SpinKitWave(
            color: Colors.lightBlueAccent,
            size: 40.0,
          ),
        ),
      );
    }

    return ResponsiveBuilder(
      builder: (context, sizingInformation) =>
          ScreenTypeLayout(
            mobile: MobileRenewMiniOffice(data),
            tablet: DesktopRenewMiniOffice(data),
            desktop: DesktopRenewMiniOffice(data),
          ),
    );
  }

  @override
  void initState() {
    super.initState();
    _loadData();
  }
  
  void _loadData() {
    HttpUtil.httpGet(
      'v1/renew-minioffice/${widget.gid}',
      businessId: Constants.BUSINESS_ID,
    ).then((value) {
      data = value;
      setState(() {});
    }).onError((error, stackTrace) {
      Utils.showMessageDialog(context, error);
    });
  }
}