import 'package:driverapp/core/enum/viewstate.dart';
import 'package:driverapp/core/viewModels/base_view_model.dart';
import 'package:driverapp/widgets/errors/app_embedded_error.dart';
import 'package:driverapp/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.Idle:
      case ViewState.BusyLocal:
      case ViewState.ErrorLocal:
        return child;
        break;
      case ViewState.Busy:
        return Expanded(child: AppCircularProgressIndicator());
        break;
      case ViewState.Error:
        return Center(
          child: AppEmbeddedError(
            error: baseViewModel.error,
          ),
        );
    }
  }
}
