import 'dart:io' show Platform;

import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:maps_launcher/maps_launcher.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:map_launcher/map_launcher.dart';
import 'dart:io' show Platform;

class pharmacyContactsPage extends StatefulWidget {
  @override
  _pharmacyContactsPageState createState() => _pharmacyContactsPageState();
}

class _pharmacyContactsPageState extends State<pharmacyContactsPage> {
  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    final latitude = "24.704016";
    final longitude = "46.676691";
    final phone = "+966112833400";
    final whatsApp = "+966558434444";
    final whatappURL_android = "whatsapp://send?phone=" + whatsApp;
    final whatappURL_ios = "https://wa.me/$whatsApp";
    final locationDescription = "Main Pharmacy OLAYA";

    return AppScaffold(
      appBarTitle: TranslationBase.of(context).contactUs,
      isShowAppBar: true,
      isShowDecPage: false,
      isPharmacy: true,
      showPharmacyCart: false,
      showHomeAppBarIcon: false,
      isMainPharmacyPages: true,
      isBottomBar: true,
      body: Column(
        children: [
          Card(
            elevation: 2,
            shape: RoundedRectangleBorder(
              side: BorderSide(color: Colors.grey[300], width: 2),
              borderRadius: BorderRadius.circular(10),
            ),
            margin: EdgeInsets.symmetric(
              horizontal: 8,
              vertical: 8,
            ),
            child: Container(
              margin: EdgeInsets.all(10),
              padding: EdgeInsets.fromLTRB(5, 15, 5, 5),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(
                  Radius.circular(15),
                ),
              ),
              child: Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                      child: projectViewModel.isArabic ?
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text("أوقات عمل مركز الخدمات الصيدلانية:",
                              //TranslationBase.of(context).contactUsTime,
                              style: TextStyle(
                                  color: Colors.grey[700],
                                  fontSize: 18,
                                  fontWeight: FontWeight.bold,
                                  letterSpacing: -0.68)),
                          SizedBox(height: 8),
                          Text(" السبت -  الأربعاء  :  من  8  صباحاً إلى  10  مساءً ",
                              //TranslationBase.of(context).contactUsTime,
                              style: TextStyle(
                                  color: Colors.grey[700],
                                  fontSize: 16,
                                  fontWeight: FontWeight.w600,
                                  letterSpacing: -0.68)),
                          SizedBox(height: 5),
                          Text("الــــخـــمــــيـــس   :  من  8  صباحاً  إلى   8   مساءً",
                              //TranslationBase.of(context).contactUsTime,
                              style: TextStyle(
                                  color: Colors.grey[700],
                                  fontSize: 16,
                                  fontWeight: FontWeight.w600,
                                  letterSpacing: -0.68)),
                          SizedBox(height: 5),
                          Text("الـــجــــمـــــعـــــة  :  من  2  ظـهـراً  إلى   8   مساءً",
                              //TranslationBase.of(context).contactUsTime,
                              style: TextStyle(
                                  color: Colors.grey[700],
                                  fontSize: 16,
                                  fontWeight: FontWeight.w600,
                                  letterSpacing: -0.68)),
                        ],
                      ):Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text("Pharmaceutical Service Center working hours: ",
                              //TranslationBase.of(context).contactUsTime,
                              style: TextStyle(
                                  color: Colors.grey[700],
                                  fontSize: 16,
                                  fontWeight: FontWeight.bold,
                                  letterSpacing: -0.68)),
                          SizedBox(height: 8),
                          Text("Sat – Wed:     from 8 AM to 10 PM",
                              //TranslationBase.of(context).contactUsTime,
                              style: TextStyle(
                                  color: Colors.grey[700],
                                  fontSize: 16,
                                  fontWeight: FontWeight.w600,
                                  letterSpacing: -0.68)),
                          SizedBox(height: 5),
                          Text("Thursday:      from 8 AM to   8 PM",
                              //TranslationBase.of(context).contactUsTime,
                              style: TextStyle(
                                  color: Colors.grey[700],
                                  fontSize: 16,
                                  fontWeight: FontWeight.w600,
                                  letterSpacing: -0.68)),
                          SizedBox(height: 5),
                          Text("Friday        :      from 2 PM to    8 PM",
                              //TranslationBase.of(context).contactUsTime,
                              style: TextStyle(
                                  color: Colors.grey[700],
                                  fontSize: 16,
                                  fontWeight: FontWeight.w600,
                                  letterSpacing: -0.68)),
                        ],
                      ),

                  ),
                  SizedBox(
                    height: 20,
                  ),
                  Row(
                    children: <Widget>[
                      InkWell(
                        onTap: () {
                          launch("tel://" + phone);
                        },
                        child: SvgPicture.asset(
                          'assets/images/pharmacy/call.svg',
                          width: 20,
                          height: 20,
                        ),
                      ),
                      SizedBox(
                        width: 20,
                      ),
                      Text(TranslationBase.of(context).phone,
                          style: TextStyle(
                              color: Colors.grey[700],
                              fontSize: 16,
                              fontWeight: FontWeight.w600,
                              letterSpacing: -0.68)),
                      SizedBox(
                        width: 30,
                      ),
                      Directionality(
                        textDirection: TextDirection.ltr,
                        child: Text("+966" +"-11-2833400",
                            style: TextStyle(
                                color: Colors.grey[700],
                                fontSize: 16,
                                fontWeight: FontWeight.w600,
                                letterSpacing: -0.68)),
                      ),
                    ],
                  ),
                  SizedBox(
                    height: 30,
                  ),
                  Row(
                    children: <Widget>[
                      InkWell(
                        onTap: () {
                          //   launch('whatsapp://send?phone='+whatsApp);
                          openWhatsApp();
                        },
                        child: SvgPicture.asset(
                          'assets/images/pharmacy/whatsapp.svg',
                          width: 20,
                          height: 20,
                        ),
                      ),
                      SizedBox(
                        width: 20,
                      ),
                      Text(TranslationBase.of(context).whatsApp,
                          style: TextStyle(
                              color: Colors.grey[700],
                              fontSize: 16,
                              fontWeight: FontWeight.w600,
                              letterSpacing: -0.68)),
                      SizedBox(
                        width: 30,
                      ),
                      Text(projectViewModel.isArabic ? "558434444 " + " 966+" :"+966 " + " 558434444",
                          style: TextStyle(
                              color: Colors.grey[700],
                              fontSize: 16,
                              fontWeight: FontWeight.w600,
                              letterSpacing: -0.68)),
                    ],
                  ),
                  SizedBox(
                    height: 30,
                  ),
                  Padding(
                    padding: const EdgeInsets.all(5.0),
                    child: Row(
                      children: <Widget>[
                        InkWell(
                          onTap: () {
                            if (Platform.isIOS) { MapLauncher.showMarker(
                            mapType: MapType.apple,
                            coords: Coords(double.parse(latitude),
                            double.parse(longitude)),
                            title: locationDescription,);
                            } else { MapLauncher.showMarker(
                            mapType: MapType.google,
                            coords: Coords(double.parse(latitude),
                            double.parse(longitude)),
                            title: locationDescription,
                            //            description: location.locationName,
                            ); }
                            // MapsLauncher.launchCoordinates(double.parse(previousModel.productLocationService[index].latitude), double.parse(previousModel.productLocationService[index].longitude), previousModel.productLocationService[index].locationDescription);
                            },
//                            MapsLauncher.launchCoordinates(
//                                double.parse(latitude),
//                                double.parse(longitude));
//                          },
                          child: SvgPicture.asset(
                            'assets/images/pharmacy/location.svg',
                            width: 20,
                            height: 20,
                          ),
                        ),
                        SizedBox(
                          width: 20,
                        ),
                        Expanded(
                          child: Text(
                              TranslationBase.of(context).contactUsLocation,
                              style: TextStyle(
                                  color: Colors.grey[700],
                                  fontSize: 16,
                                  fontWeight: FontWeight.w600,
                                  letterSpacing: -0.68)),
                        ),
                      ],
                    ),
                  ),
                  SizedBox(
                    height: 50,
                  ),
                  Center(
                    child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: <Widget>[
                          IconButton(
                            icon: new Image.asset(
                                'assets/images/new-design/facebook.png'),
                            tooltip: 'facebook',
                            iconSize: 48,
                            onPressed: () {
                              setState(() {
                                launch("https://facebook.com/HMG.pharmacy");
                                //  launch("https://www.facebook.com/DrSulaimanAlHabib?ref=tn_tnmn");
                              });
                            },
                          ),
                          IconButton(
                            icon: new Image.asset(
                                'assets/images/new-design/twitter.png'),
                            tooltip: 'Twitter',
                            iconSize: 48,
                            onPressed: () {
                              setState(() {
                                launch("https://twitter.com/HMG_pharmacy");
                              });
                            },
                          ),
                          IconButton(
                            icon: new Image.asset(
                                'assets/images/pharmacy/instagram.png'),
                            tooltip: 'Instagram',
                            iconSize: 48,
                            onPressed: () {
                              setState(() {
                                launch("https://instagram.com/HMG_pharmacy");
                              });
                            },
                          ),
                        ]),
                  )
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  openWhatsApp() async {
    // bool Platform.isIOS = Theme.of(context).platform == TargetPlatform.iOS;
    var whatsapp = "+966558434444";
    var whatsappURL_android = "whatsapp://send?phone=" + whatsapp;
    var whatappURL_ios = "https://wa.me/$whatsapp";
    if (Platform.isIOS) {
      // for iOS phone only
      // if (await canLaunch(whatappURL_ios)) {
      await launch(whatappURL_ios, forceSafariVC: false);
      // } else {}
    } else {
      // android
      // if (await canLaunch(whatsappURL_android)) {
      await launch(whatsappURL_android);
      // } else {}
    }
  }
}
