import 'package:diplomaticquarterapp/core/model/ImagesInfo.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/qr_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.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:maps_launcher/maps_launcher.dart';
import 'package:provider/provider.dart';

import '../../d_q_icons_icons.dart';

class ParkingPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<QrViewModel>(
      onModelReady: (model) => model.getIsSaveParking(),
      builder: (_, model, widget) => AppScaffold(
        isShowAppBar: true,
        showNewAppBar: true,
        showNewAppBarTitle: true,
        appBarTitle: TranslationBase.of(context).parking,
        description: TranslationBase.of(context).parkingDescription,
        imagesInfo: [ImagesInfo(imageAr: 'assets/images/bc_parking.png', imageEn: 'assets/images/bc_parking.png', isAsset: true)],
        body: SingleChildScrollView(
          padding: EdgeInsets.all(12),
          child: !model.isSavePark
              ? Column(
                  children: <Widget>[
                    Texts(
                      TranslationBase.of(context).parkingDescription,
                      fontWeight: FontWeight.normal,
                      fontSize: 15,
                    ),
                    SizedBox(
                      height: 12,
                    ),
                    Image.asset(
                      'assets/images/timeline_bg.png',
                      width: double.infinity,
                    )
                  ],
                )
              : Column(
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        Expanded(
                          child: Container(
                            child: Icon(/*Icons.landscape*/ DQIcons.parking_icon, size: 130),
                          ),
                        ),
                        SizedBox(
                          width: 15,
                        ),
                        Expanded(
                          child: Container(
                            height: 150,
                            padding: EdgeInsets.all(8),
                            decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.white, shape: BoxShape.rectangle),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                Texts(model.qrParkingModel.parkingDescriptionN),
                                Divider(
                                  height: 3,
                                ),
                                Texts(model.qrParkingModel.rowDescriptionN)
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 15,
                    ),
                    Container(
                      padding: EdgeInsets.all(8),
                      width: double.infinity,
                      decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.white, shape: BoxShape.rectangle),
                      height: 70,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Texts(TranslationBase.of(context).showMyPark),
                          Texts(projectViewModel.isArabic ? model.qrParkingModel.floorDescriptionN : model.qrParkingModel.floorDescription),
                        ],
                      ),
                    ),
                    SizedBox(
                      height: 15,
                    ),
                    Container(
                      decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.white, shape: BoxShape.rectangle),
                      padding: EdgeInsets.all(8),
                      width: double.infinity,
                      height: 70,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Texts(TranslationBase.of(context).gate),
                          Texts(projectViewModel.isArabic ? model.qrParkingModel.gateDescriptionN : model.qrParkingModel.gateDescription),
                        ],
                      ),
                    ),
                    SizedBox(
                      height: 15,
                    ),
                    Container(
                      decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.white, shape: BoxShape.rectangle),
                      padding: EdgeInsets.all(8),
                      width: double.infinity,
                      height: 70,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Texts(TranslationBase.of(context).building),
                          Texts(projectViewModel.isArabic ? model.qrParkingModel.buildingDescriptionN : model.qrParkingModel.buildingDescription),
                        ],
                      ),
                    ),
                    SizedBox(
                      height: 15,
                    ),
                    Container(
                      padding: EdgeInsets.all(8),
                      decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.white, shape: BoxShape.rectangle),
                      width: double.infinity,
                      height: 70,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Texts(TranslationBase.of(context).branch),
                          Texts(projectViewModel.isArabic ? model.qrParkingModel.branchDescriptionN : model.qrParkingModel.branchDescription),
                        ],
                      ),
                    ),
                    SizedBox(
                      height: 15,
                    ),
                  ],
                ),
        ),
        bottomSheet: !model.isSavePark
            ? Container(
                color: Theme.of(context).scaffoldBackgroundColor,
                height: MediaQuery.of(context).size.height * 0.10,
                width: double.infinity,
                child: Column(
                  children: <Widget>[
                    Container(
                      width: MediaQuery.of(context).size.width * 0.9,
                      child: DefaultButton(TranslationBase.of(context).readBarcode, () => {model.readQr()}),
                    ),
                  ],
                ),
              )
            : Container(
                height: MediaQuery.of(context).size.height * 0.15,
                width: double.infinity,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Container(
                      width: MediaQuery.of(context).size.width * 0.9,
                      child: DefaultButton(
                          TranslationBase.of(context).showMyPark,
                          () => {
                                MapsLauncher.launchCoordinates(
                                  model.qrParkingModel.latitude,
                                  model.qrParkingModel.longitude,
                                ),
                              }),
                    ),
                    SizedBox(
                      height: 12,
                    ),
                    InkWell(
                        onTap: () => model.clearParking(),
                        child: Texts(
                          TranslationBase.of(context).clearMyData,
                          color: Colors.red,
                          decoration: TextDecoration.underline,
                        ))
                  ],
                ),
              ),
      ),
    );
  }
}
