import 'package:hmg_patient_app/core/model/contactus/get_hmg_locations.dart';
import 'package:hmg_patient_app/core/model/prescriptions/prescription_report.dart';
import 'package:hmg_patient_app/core/viewModels/medical/prescriptions_view_model.dart';
import 'package:hmg_patient_app/pages/base/base_view.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/widgets/data_display/text.dart';
import 'package:hmg_patient_app/widgets/hospital_location.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.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,
        showNewAppBar: true,
        showNewAppBarTitle: true,
        appBarTitle: TranslationBase.of(context).availability,
        baseViewModel: model,
        body: Column(
          children: [
            Padding(
              padding: const EdgeInsets.fromLTRB(21, 21, 21, 10),
              child: Container(
                width: double.infinity,
                padding: const EdgeInsets.only(left: 12, right: 12, top: 12, bottom: 12),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(
                      Radius.circular(10.0),
                    ),
                    boxShadow: [
                      BoxShadow(
                        color: Color(0xff000000).withOpacity(.05),
                        //spreadRadius: 5,
                        blurRadius: 27,
                        offset: Offset(0, -3),
                      ),
                    ],
                    color: Colors.white),
                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
                ? Expanded(
                    child: ListView.builder(
                      scrollDirection: Axis.vertical,
                      padding: EdgeInsets.fromLTRB(21, 11, 21, 21),
                      physics: BouncingScrollPhysics(),
                      itemBuilder: (context, index) {
                        GetHMGLocationsModel location = GetHMGLocationsModel();
                        location.locationName = model.pharmacyPrescriptionsList[index].locationDescription;
                        location.cityName = model.pharmacyPrescriptionsList[index].cityName;
                        location.phoneNumber = model.pharmacyPrescriptionsList[index].phoneNumber;
                        location.latitude = model.pharmacyPrescriptionsList[index].latitude;
                        location.longitude = model.pharmacyPrescriptionsList[index].longitude;
                        location.distanceInKilometers = model.pharmacyPrescriptionsList[index].distanceInKilometers;
                        return HospitalLocation(location, showCity: true);
                      },
                      itemCount: model.pharmacyPrescriptionsList.length,
                    ),
                  )
                : Padding(
                    padding: const EdgeInsets.only(top: 65.0),
                    child: Texts(
                      TranslationBase.of(context).thisItemIsNotAvailable,
                      textAlign: TextAlign.center,
                    ),
                  ),
          ],
        ),
      ),
    );
  }
}
