import 'package:doctor_app_flutter/core/enum/view_state.dart';
import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'app_loader_widget.dart';
import 'errors/error_message.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.grey[100],
      child: buildBaseViewWidget(),
    );
  }

  buildBaseViewWidget() {
    switch (baseViewModel.state) {
      case ViewState.ErrorLocal:
      case ViewState.Idle:
      case ViewState.BusyLocal:
        return child;
        break;
      case ViewState.Busy:
        return AppLoaderWidget();
        break;
      case ViewState.Error:
        return ErrorMessage(
          error: baseViewModel.error!,
        );
        break;
    }
  }
}
