import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart';
import 'package:diplomaticquarterapp/widgets/errors/app_embedded_error.dart';
import 'package:diplomaticquarterapp/widgets/progress_indicator/app_circular_progress_Indeicator.dart';
import 'package:flutter/cupertino.dart';

class NetworkBaseView extends StatelessWidget {
  final BaseViewModel baseViewModel;
  final Widget child;

  NetworkBaseView({Key key, this.baseViewModel, this.child});

  @override
  Widget build(BuildContext context) {
    return Container(
      child: buildBaseViewWidget(),
    );
  }

  buildBaseViewWidget() {
    switch (baseViewModel.state) {
      case ViewState.ErrorLocal:
      case ViewState.Idle:
      case ViewState.BusyLocal:
        return child;
        break;
      case ViewState.Busy:
        return AppCircularProgressIndicator();
        break;
      case ViewState.Error:
        return Center(
          child: AppEmbeddedError(
            error: baseViewModel.error,
          ),
        );
        break;
    }
  }
}
