import 'package:diplomaticquarterapp/core/viewModels/contactus/findus_view_model.dart';
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/viewModels/contactus/livechat_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/widgets/buttons/button.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:url_launcher/url_launcher.dart';

class PhamaciesLiveChatPage extends StatefulWidget {
  @override
  _PhamaciesLiveChatPageState createState() => _PhamaciesLiveChatPageState();
}

class _PhamaciesLiveChatPageState extends State<PhamaciesLiveChatPage> {
  int tappedIndex;
  String chat;

  @override
  void initState() {
    super.initState();
    tappedIndex = -1;
    chat = "";
  }

  @override
  Widget build(BuildContext context) {
    return BaseView<LiveChatViewModel>(
      onModelReady: (model) => model.getLiveChatRequestOrders(),
      builder: (_, model, widget) => AppScaffold(
        baseViewModel: model,
        body: SingleChildScrollView(
          child: Container(
            margin: EdgeInsets.only(left: 15, right: 15),
            child: Column(
              children: [
                SizedBox(
                  height: 20,
                ),
                Container(
                  width: double.infinity,
                  height: 200,
                  decoration: BoxDecoration(
                    image: DecorationImage(
                        image: ExactAssetImage(''), fit: BoxFit.cover),
                  ),
                  child: Texts(
                    'You can now talk directly to the pharmacist by chat or request a call back',
                    color: Colors.black,
                    textAlign: TextAlign.center,
                  ),
                ),
                ///////////

                SizedBox(
                  height: 100,
                ),
              ],
            ),
          ),
        ),
        bottomSheet: Container(
          height: MediaQuery.of(context).size.height * 0.13,
          width: double.infinity,
          padding: EdgeInsets.all(8.0),
          child: Center(
            child: Container(
              height: MediaQuery.of(context).size.height * 0.1,
              width: MediaQuery.of(context).size.width * 0.8,
              child: Button(
                label: 'ٍStart',
                loading: model.state == ViewState.BusyLocal,
                onTap: () {
                  print("chat=" + chat);
                  chat =
                      "http://chat.dshmg.com:7788/EPharmacyChat/EIndex.aspx?CustomerID=undefined&Name=${model.user.firstName}&MobileNo=${model.user.mobileNumber}&Language=1";
                  launch(chat);
                },
              ),
            ),
          ),
        ),
      ),
    );
  }
}
