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

import '../models/business.dart';
import '../store/actions.dart';
import '../store/store.dart';
import '../utils/http_util.dart';
import '../utils/utils.dart';
import '../widgets/desktop/desktop_contact_us.dart';
import '../widgets/mobile/mobile_contact_us.dart';

class ContactUs extends StatefulWidget {
  final int businessId;

  const ContactUs({this.businessId, Key? key}) :
      super(key: key);

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

class ContactUsState extends State<ContactUs> {
  Business business;

  @override
  Widget build(BuildContext context) {

    store.dispatch(UpdateContext(context));

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

    return ResponsiveBuilder(
      builder: (context, sizingInformation) =>
          ScreenTypeLayout(
            mobile: MobileContactUs(business),
            tablet: DesktopContactUs(business),
            desktop: DesktopContactUs(business),
          ),
    );
  }

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

  void loadData() {
    HttpUtil.httpGet(
      'v1/get-business',
      businessId: widget.businessId,
    ).then((value) {
      business = Business.fromJson(value);
      setState(() {});
    }).onError((error, stackTrace) {
      Utils.showMessageDialog(context, error);
    });
  }
}