import 'package:driverapp/app-icons/driver_app_icons.dart';
import 'package:driverapp/core/viewModels/orders_view_model.dart';
import 'package:driverapp/pages/base/base_view.dart';
import 'package:driverapp/pages/delivery/delivery_confirmed_page.dart';
import 'package:driverapp/widgets/bottom_sheet/action_sheet_button.dart';
import 'package:driverapp/widgets/bottom_sheet/custom_bottom_sheet.dart';
import 'package:driverapp/widgets/buttons/secondary_button.dart';
import 'package:driverapp/widgets/data_display/dialog/custom_dialog.dart';
import 'package:driverapp/widgets/data_display/text.dart';
import 'package:driverapp/widgets/delivery/customer_brief_card.dart';
import 'package:driverapp/widgets/delivery/delivery_action_button.dart';
import 'package:driverapp/widgets/delivery/package_content.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';

import '../../uitl/translations_delegate_base.dart';
import '../../widgets/others/app_scaffold_widget.dart';

class InformationPage extends StatelessWidget {
  final dynamic item;
  int orderStatus;

  InformationPage(this.item);

  @override
  Widget build(BuildContext context) {
    return BaseView<OrdersViewModel>(
      builder: (BuildContext context, OrdersViewModel model, Widget child) =>
          AppScaffold(
        body: Container(
          color: Color(0xff41bdbb),
          child: Container(
            color: Color(0xff41bdbb),
            child: ListView(
              children: <Widget>[
                Column(
                  children: <Widget>[
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        Container(
                          margin: EdgeInsets.only(
                            right:
                                MediaQuery.of(context).size.width * 0.15, //50
                          ),
                          child: IconButton(
                            color: Colors.white,
                            iconSize: 50,
                            icon: Icon(Icons.arrow_back),
                            onPressed: () {
                              Navigator.pop(context);
                            },
                          ),
                        ),
                        Container(
                          child: Text(
                            TranslationBase.of(context).deliveryInfo,
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 20,
                            ),
                          ),
                        ),
                      ],
                    ),
                    Stack(
                      children: <Widget>[
                        Container(
                          width: MediaQuery.of(context).size.width, //400,
                          height: MediaQuery.of(context).size.width, //500,
                        ),
                        Container(
                          width: MediaQuery.of(context).size.width * 1,
                          //800,
                          height: MediaQuery.of(context).size.width * 1.5,
                          //700,
                          margin: EdgeInsets.only(
                            top: MediaQuery.of(context).size.width * 0.3, //100
                          ),
                          decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.only(
                                topLeft: Radius.circular(45),
                                topRight: Radius.circular(45)),
                          ),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: <Widget>[
                              SizedBox(
                                height: MediaQuery.of(context).size.width *
                                    0.2, //170,
                              ),
                              Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: <Widget>[
                                  delivery_info_button(
                                    btnColor: Color(0xfff44336),
                                    btnIcon: Icon(
                                      Icons.near_me,
                                      size: 30,
                                      color: Colors.white,
                                    ),
                                    btnName:
                                        TranslationBase.of(context).location,
                                    btnFunction: () {},
                                  ),
                                  delivery_info_button(
                                    btnColor: Colors.green,
                                    btnIcon: Icon(
                                      Icons.whatshot,
                                      size: 30,
                                      color: Colors.white,
                                    ),
                                    btnName: 'Whatsapp',
                                    btnFunction: () {},
                                  ),
                                  delivery_info_button(
                                    btnColor: Colors.orangeAccent,
                                    btnIcon: Icon(
                                      Icons.mail_outline,
                                      size: 30,
                                      color: Colors.white,
                                    ),
                                    btnName: TranslationBase.of(context).sms,
                                    btnFunction: () {},
                                  ),
                                  delivery_info_button(
                                    btnColor: Color(0xff41bdbb),
                                    btnIcon: Icon(
                                      Icons.phone,
                                      size: 30,
                                      color: Colors.white,
                                    ),
                                    btnName: TranslationBase.of(context).call,
                                    btnFunction: () {},
                                  ),
                                ],
                              ),
                              SizedBox(
                                height: MediaQuery.of(context).size.width *
                                    0.1, //30,
                              ),
                              Container(
                                margin: EdgeInsets.only(
                                  left: MediaQuery.of(context).size.width *
                                      0.05, //15,
                                  right: MediaQuery.of(context).size.width *
                                      0.02, //15
                                ),
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: <Widget>[
                                    Text(
                                      TranslationBase.of(context)
                                          .packageContent,
                                      style: TextStyle(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 20),
                                    ),
                                    SizedBox(
                                      height:
                                          MediaQuery.of(context).size.width *
                                              0.05, //20,
                                    ),
                                    Column(
                                      children: List.generate(
                                          item.itemsQuantitiesList.length,
                                          (index) {
                                        return package_content(
                                          packageName: item
                                              .itemsQuantitiesList[index]
                                              .itemName
                                              .toString(),
                                          //'Panadol Extra 50 tablet',
                                          packageCount: item
                                              .itemsQuantitiesList[index]
                                              .quantity
                                              .toString(),
                                        );
                                      }),
                                    ),
                                    SizedBox(
                                      height:
                                          MediaQuery.of(context).size.width *
                                              0.01, //10,
                                    ),
                                  ],
                                ),
                              ),
                              SizedBox(
                                height: MediaQuery.of(context).size.width *
                                    0.1, //30,
                              ),
                              FlatButton(
                                color: Color(0xff41bdbb),
                                padding: EdgeInsets.only(
                                  right: MediaQuery.of(context).size.width *
                                      0.3, //100,
                                  left: MediaQuery.of(context).size.width *
                                      0.3, //100,
                                  bottom: MediaQuery.of(context).size.width *
                                      0.035, //15,
                                  top: MediaQuery.of(context).size.width *
                                      0.035, //15
                                ),
                                shape: RoundedRectangleBorder(
                                  borderRadius: new BorderRadius.circular(30.0),
                                  side: BorderSide(color: Color(0xff41bdbb)),
                                ),
                                child: Text(
                                  TranslationBase.of(context).clientReached,
                                  style: TextStyle(
                                      color: Colors.white,
                                      fontWeight: FontWeight.bold,
                                      fontSize: 16),
                                ),
                                onPressed: () {
                                  model.showBottomSheet();
                                },
                              ),
                            ],
                          ),
                        ),
                        CustomerBrief(
                            itemId: item.patientID,
                            customerFirstName: item.firstName,
                            customerLastName: item.lastName,
                            mobileNo: item.mobileNumber,
                            totalPayment: item.amount,
                            deliveryTime: item.orderCreatedOn),
                      ],
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),
        bottomSheet: !model.isBottomSheetAppear
            ? Container(
                width: 0,
                height: 0,
              )
            : CustomBottomSheet(
                children: [
                  SizedBox(
                    height: 10,
                  ),
                  Center(
                    child: Texts(
                      'Select Action',
                      color: Colors.black,
                      fontSize: 22,
                    ),
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  FractionallySizedBox(
                    widthFactor: 0.9,
                    child: Column(
                      children: <Widget>[
                        SizedBox(
                          height: 3,
                          child: Container(
                            color: Hexcolor("#D5D5D5"),
                          ),
                        ),
                        SizedBox(
                          height: 6,
                        ),
                        ActionSheetButton(
                          label: "Delivered",
                          icon: DriverApp.deliverd_icon,
                          onTap: () {
                            selectAction(context, 1, model);
                          },
                        ),
                        SizedBox(
                          height: 6,
                        ),
                        ActionSheetButton(
                          label: "Not Available",
                          icon: DriverApp.not_available,
                          onTap: () {
                            selectAction(context, 2, model);
                          },
                        ),
                        SizedBox(
                          height: 6,
                        ),
                        ActionSheetButton(
                          label: "Rejected",
                          icon: DriverApp.rejected_icon,
                          onTap: () {
                            selectAction(context, 3, model);
                          },
                        ),
                        SizedBox(
                          height: 6,
                        ),
                        ActionSheetButton(
                          label: "Not Reachable",
                          icon: DriverApp.not_reachable_icon,
                          onTap: () {
                            selectAction(context, 4, model);
                          },
                        ),
                      ],
                    ),
                  ),
                ],
              ),
      ),
    );
  }

  selectAction(BuildContext context, orderStatus, OrdersViewModel model) {
    String orderStatusText;
    switch (orderStatus) {
      case 1:
        orderStatusText = "Delivered";
        break;
      case 2:
        orderStatusText = "Not Available";
        break;
      case 3:
        orderStatusText = "Rejected";
        break;
      case 4:
        orderStatusText = "Not Reachable";
        break;
    }
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return CustomDialog(
              child: Container(
            child: Column(
              children: <Widget>[
                SizedBox(
                  height: 30,
                ),
                Text(
                  'you have selected:',
                  style: TextStyle(
                      fontWeight: FontWeight.w500,
                      color: Colors.black,
                      fontSize: 15.0),
                ),
                Text(
                  orderStatusText,
                  style: TextStyle(
                      color: Theme.of(context).primaryColor, fontSize: 18.0),
                ),
                SizedBox(
                  height: 40,
                ),
                FractionallySizedBox(
                  widthFactor: 0.8,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: <Widget>[
                      Texts(
                        'Are you sure?',
                        color: Colors.black,
                        fontSize: 20,
                      ),
                      SizedBox(
                        height: 10,
                      ),
                      SecondaryButton(
                        label: "Confirm",
                        onTap: () {
                          Navigator.of(context).pop();
                          model.hideBottomSheet();
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (context) => DeliveryConfirmedPage(item),
                            ),
                          );
                        },
                      ),
                      SizedBox(
                        height: 10,
                      ),
                      SecondaryButton(
                        label: "Cancel",
                        onTap: () {
                          model.hideBottomSheet();
                          Navigator.of(context).pop();
                        },
                      ),
                    ],
                  ),
                )
              ],
            ),
          ));
        });
  }
}
