import 'package:diplomaticquarterapp/core/model/prescriptions/prescription_report.dart';
import 'package:diplomaticquarterapp/core/model/prescriptions/prescription_report_inp.dart';
import 'package:diplomaticquarterapp/core/viewModels/medical/prescriptions_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:maps_launcher/maps_launcher.dart';
import 'package:url_launcher/url_launcher.dart';

class PharmacyForPrescriptionsPage extends StatelessWidget {
  final itemID;
  final PrescriptionReport prescriptionReport;

  PharmacyForPrescriptionsPage({Key key, this.itemID, this.prescriptionReport});

  @override
  Widget build(BuildContext context) {
    return BaseView<PrescriptionsViewModel>(
      onModelReady: (model) => model.getListPharmacyForPrescriptions(itemId: itemID),
      builder: (_, model, widget) => AppScaffold(
        isShowAppBar: true,
        appBarTitle: TranslationBase.of(context).availability,
        baseViewModel: model,
        body: Column(
          children: [
            Container(
              width: double.infinity,
              margin: EdgeInsets.only(top: 10, left: 10, right: 10),
              padding: EdgeInsets.all(8.0),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(
                  Radius.circular(10.0),
                ),
                border: Border.all(color: Colors.grey[200], width: 0.5),
              ),
              child: Row(
                children: <Widget>[
                  ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(5)),
                    child: Image.network(
                      prescriptionReport.imageSRCUrl,
                      fit: BoxFit.cover,
                      width: 60,
                      height: 70,
                    ),
                  ),
                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Center(
                        child: Texts(prescriptionReport.itemDescription.isNotEmpty
                            ? prescriptionReport.itemDescription
                            : prescriptionReport.itemDescriptionN ?? ''),
                      ),
                    ),
                  )
                ],
              ),
            ),
            model.pharmacyPrescriptionsList.isNotEmpty == true
                ? ListView.builder(
                    scrollDirection: Axis.vertical,
                    shrinkWrap: true,
                    itemBuilder: (context, index) => Container(
                      width: double.infinity,
                      margin: EdgeInsets.only(top: 10, left: 10, right: 10),
                      padding: EdgeInsets.all(8.0),
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(
                          Radius.circular(10.0),
                        ),
                        border: Border.all(color: Colors.grey[200], width: 0.5),
                      ),
                      child: Row(
                        children: <Widget>[
                          ClipRRect(
                            borderRadius: BorderRadius.all(Radius.circular(5)),
                            child: Image.network(
                              model.pharmacyPrescriptionsList[index].projectImageURL,
                              fit: BoxFit.cover,
                              width: 60,
                              height: 70,
                            ),
                          ),
                          Expanded(
                            child: Padding(
                              padding: const EdgeInsets.all(8.0),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  Texts(model.pharmacyPrescriptionsList[index].locationDescription),
                                  SizedBox(
                                    height: 5,
                                  ),
                                  Texts(model.pharmacyPrescriptionsList[index].cityName),
                                ],
                              ),
                            ),
                          ),
                          InkWell(
                            onTap: () {
                              MapsLauncher.launchCoordinates(
                                  double.parse(model.pharmacyPrescriptionsList[index].latitude),
                                  double.parse(model.pharmacyPrescriptionsList[index].longitude));
                            },
                            child: Icon(
                              Icons.pin_drop,
                              size: 18,
                              color: Colors.red[900],
                            ),
                          ),
                          SizedBox(
                            width: 15,
                          ),
                          InkWell(
                            onTap: Feedback.wrapForTap(() {
                              launch("tel://${model.pharmacyPrescriptionsList[index].phoneNumber}");
                            }, context),
                            child: Container(
                              child: Icon(
                                Icons.call,
                                size: 18,
                                color: Colors.red[900],
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                    itemCount: model.pharmacyPrescriptionsList.length,
                  )
                : Padding(
                    padding: const EdgeInsets.only(top: 65.0),
                    child: Texts(
                      TranslationBase.of(context).thisItemIsNotAvailable,
                      textAlign: TextAlign.center,
                    ),
                  ),
          ],
        ),
      ),
    );
  }
}
