import 'package:driverapp/config/size_config.dart';
import 'package:driverapp/core/enum/viewstate.dart';
import 'package:driverapp/core/viewModels/orders_view_model.dart';
import 'package:driverapp/pages/base/base_view.dart';
import 'package:driverapp/uitl/translations_delegate_base.dart';
import 'package:driverapp/widgets/buttons/secondary_button.dart';
import 'package:flutter/material.dart';

import '../text.dart';

class CustomDialog extends StatelessWidget {
//  final Widget child;
  final String orderStatusText;
  final Function callService;
  final OrdersViewModel model;

  CustomDialog({this.orderStatusText, this.callService, this.model});

  @override
  Widget build(BuildContext context) {
    return BaseView<OrdersViewModel>(
      builder: (_, model, w) => Center(
        child: Container(
          height: SizeConfig.isPortrait
              ? MediaQuery.of(context).size.height * 0.49
              : MediaQuery.of(context).size.height * 0.90,
          width: MediaQuery.of(context).size.width * 0.95,
          child: Dialog(
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(15),
            ),
            elevation: 0.0,
            backgroundColor: Colors.white,
            child: Container(
              child: Column(
                children: <Widget>[
                  SizedBox(
                    height: 30,
                  ),
                  Text(
                    TranslationBase.of(context).youHaveSelected,
                    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: SizeConfig.isPortrait ? 0.9 : 0.8,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: <Widget>[
                        Texts(
                          TranslationBase.of(context).areYouSure,
                          color: Colors.black,
                          fontSize: 20,
                        ),
                        SizedBox(
                          height: 10,
                        ),
                        FractionallySizedBox(
                          widthFactor: 0.9,
                          child: Column(
                            children: <Widget>[
                              SecondaryButton(
                                label: TranslationBase.of(context).confirm,
                                loading: model.state == ViewState.BusyLocal,
                                onTap: () {
                                  model.setState(ViewState.BusyLocal);
                                  callService();
                                },
                              ),
                              SizedBox(
                                height: 10,
                              ),
                              SecondaryButton(
                                label: TranslationBase.of(context).canceled,
                                onTap: () {
                                  model.hideBottomSheet();
                                  Navigator.of(context).pop();
                                },
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  )
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
