import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/order_detail.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/payment-checkout-data.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/order_model_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/screens/cart-page/payment_bottom_widget.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/screens/payment-method-select-page.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/widgets/ProductOrderPreviewItem.dart';
import 'package:diplomaticquarterapp/pages/pharmacy/pharmacyAddresses/PharmacyAddresses.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/in_app_browser/InAppBrowser.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class LakumWidget extends StatefulWidget {
  final OrderPreviewViewModel model;

  LakumWidget(this.model);

  @override
  _LakumWidgetState createState() => _LakumWidgetState();
}

class _LakumWidgetState extends State<LakumWidget> {
  TextEditingController _pointsController = new TextEditingController();

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectProvider = Provider.of(context);

    return Container(
      color: Colors.white,
      padding: EdgeInsets.symmetric(vertical: 12, horizontal: 12),
      child: Row(
        children: [
          Image.asset(
            "assets/images/pharmacy_module/lakum/lakum_checkout.png",
            width: 30.0,
            fit: BoxFit.scaleDown,
          ),
          Container(
            decoration: BoxDecoration(color: Color(0x99ffffff)),
            padding: const EdgeInsets.symmetric(horizontal: 8),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Texts(
                  "${TranslationBase.of(context).lakumPoints}",
                  fontSize: 12,
                  fontWeight: FontWeight.bold,
                ),
                Texts(
                  "${widget.model.paymentCheckoutData.lacumInformation.lakumInquiryInformationObjVersion.pointsBalanceAmount}",
                  fontSize: 12,
                  fontWeight: FontWeight.normal,
                ),
              ],
            ),
          ),
          Expanded(
            child: Container(
              decoration: BoxDecoration(color: Color(0x99ffffff)),
              padding: const EdgeInsets.symmetric(horizontal: 8),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  Texts(
                    "${TranslationBase.of(context).riyal}",
                    fontSize: 12,
                    fontWeight: FontWeight.bold,
                  ),
                  Container(
                    margin: projectProvider.isArabic
                        ? EdgeInsets.only(right: 4)
                        : EdgeInsets.only(left: 4),
                    width: 60,
                    height: 50,
                    child: TextField(
                      decoration: InputDecoration(
                        border: OutlineInputBorder(
                          borderSide:
                              BorderSide(color: Colors.black, width: 0.2),
                          gapPadding: 0,
                          borderRadius: projectProvider.isArabic
                              ? BorderRadius.only(
                                  topRight: Radius.circular(8),
                                  bottomRight: Radius.circular(8))
                              : BorderRadius.only(
                                  topLeft: Radius.circular(8),
                                  bottomLeft: Radius.circular(8)),
                        ),
                        disabledBorder: OutlineInputBorder(
                          borderSide:
                              BorderSide(color: Colors.black, width: 0.4),
                          gapPadding: 0,
                          borderRadius: BorderRadius.only(
                              topLeft: Radius.circular(8),
                              bottomLeft: Radius.circular(8)),
                        ),
                      ),
                      controller: _pointsController,
                      keyboardType: TextInputType.number,
                      style: TextStyle(
                        fontSize: 14,
                        color: widget
                                    .model
                                    .paymentCheckoutData
                                    .lacumInformation
                                    .lakumInquiryInformationObjVersion
                                    .pointsBalanceAmount >
                                0
                            ? Colors.black
                            : Colors.grey,
                      ),
                      enabled: widget
                                  .model
                                  .paymentCheckoutData
                                  .lacumInformation
                                  .lakumInquiryInformationObjVersion
                                  .pointsBalanceAmount ==
                              0
                          ? false
                          : true,
                      onChanged: (val) {
                        var value = int.tryParse(val);
                        if (value != null &&
                            value <=
                                widget
                                    .model
                                    .paymentCheckoutData
                                    .lacumInformation
                                    .lakumInquiryInformationObjVersion
                                    .pointsBalanceAmount) {
                          widget.model.paymentCheckoutData.usedLakumPoints =
                              value;
                        } else {
                          widget.model.paymentCheckoutData.usedLakumPoints = 0;
                        }
                        _pointsController.text =
                            "${widget.model.paymentCheckoutData.usedLakumPoints}";
                      },
                    ),
                  ),
                  Container(
                    height: 50,
                    padding: EdgeInsets.symmetric(horizontal: 8, vertical: 12),
                    decoration: new BoxDecoration(
                      color: Color(0xff3666E0),
                      shape: BoxShape.rectangle,
                      borderRadius: projectProvider.isArabic
                          ? BorderRadius.only(
                              topLeft: Radius.circular(6),
                              bottomLeft: Radius.circular(6))
                          : BorderRadius.only(
                              topRight: Radius.circular(6),
                              bottomRight: Radius.circular(6)),
                      border: Border.fromBorderSide(BorderSide(
                        color: Color(0xff3666E0),
                        width: 0.8,
                      )),
                    ),
                    child: Texts(
                      "${TranslationBase.of(context).use}",
                      fontSize: 12,
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
