import 'package:diplomaticquarterapp/core/viewModels/er/near_hospital_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/location_util.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/pages/ErService/widgets/card_common.dart';
import 'widgets/card_position.dart';

class NearestEr extends StatelessWidget {
  static const String _url = "assets/images/";

  int appointmentNo;
  int projectID;

  NearestEr({this.appointmentNo, this.projectID});

  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    final double itemHeight = (size.height - kToolbarHeight - 24) / 2;
    final double itemWidth = size.width / 2;

    return BaseView<NearHospitalViewModel>(
      onModelReady: appointmentNo != null && projectID != null
          ? (model) => model.getProjectAvgERWaitingTimeOrders(
              id: appointmentNo, projectID: projectID)
          : (model) => model.getProjectAvgERWaitingTimeOrders(),
      builder: (_, mode, widget) => AppScaffold(
        isShowAppBar: true,
        isShowDecPage: false,
        appBarTitle: TranslationBase.of(context).NearestEr,
        baseViewModel: mode,
        body: mode.ProjectAvgERWaitingTimeModeList.length > 0
            ? Container(
                child: ListView(
                  children: <Widget>[
                    Text(
                        "${TranslationBase.of(context).NearestErDesc}",
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            fontSize: 18.0,
                            letterSpacing: 1.0,
                            fontWeight: FontWeight.w900,
                            color: new Color(0xFF60686b))),
                    Container(
                      margin: EdgeInsets.fromLTRB(2.0, 10.0, 0.0, 10.0),
                      child: GridView.count(
                        crossAxisCount: 2,
                        childAspectRatio: (itemWidth / itemWidth),
                        crossAxisSpacing: 10,
                        mainAxisSpacing: 10,
                        controller:
                            new ScrollController(keepScrollOffset: false),
                        shrinkWrap: true,
                        padding: const EdgeInsets.all(4.0),
                        children: List.generate(7, (index) {
                          return Container(
                            child: CardPosition(
                              text: mode
                                  .ProjectAvgERWaitingTimeModeList[index]
                                  .projectName
                                  .toString(),
                              image:
                              'assets/images/new-design/find_us_icon.png',
                              subText: mode
                                  .ProjectAvgERWaitingTimeModeList[index]
                                  .distanceInKilometers
                                  .toString(),
                              type: mode
                                  .ProjectAvgERWaitingTimeModeList[index].iD
                                  .toString(),
                              telephone: mode
                                  .ProjectAvgERWaitingTimeModeList[index]
                                  .phoneNumber
                                  .toString(),
                              networkImage: mode
                                  .ProjectAvgERWaitingTimeModeList[index]
                                  .projectImageURL
                                  .toString(),
                              latitude: mode
                                  .ProjectAvgERWaitingTimeModeList[index]
                                  .latitude,
                              longitude: mode
                                  .ProjectAvgERWaitingTimeModeList[index]
                                  .longitude,
                              projectname: mode
                                  .ProjectAvgERWaitingTimeModeList[index]
                                  .projectName,
                              cardSize: itemWidth,
                            ),
                          );
                        }),
                      ),
                    ),
                  ],
                ),
              )
            : Center(
                child: Texts('No Data'),
              ),
      ),
    );
  }
}
