import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/controller/mh_controller/book_info_controller.dart';
import 'package:vbvs_app/pages/common/selectDialog.dart';
import 'package:vbvs_app/pages/mh_page/app_map_location.dart';

import '../../common/color/appFontsize.dart';
import '../../common/util/MyUtils.dart';

class ExperienceStoreWidget extends GetView {
  int index;
  Map data;

  ExperienceStoreWidget({required this.index, required this.data}) {}

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsetsDirectional.fromSTEB(30.rpx, 0, 30.rpx, 0),
      child: Container(
        width: MediaQuery.sizeOf(context).width,
        // height: MediaQuery.sizeOf(context).height * 0.187,
        decoration: BoxDecoration(
          color: Color(0XFF003058),
          borderRadius: BorderRadius.circular(16),
        ),

        child: Container(
          width: MediaQuery.sizeOf(context).width,
          margin: EdgeInsetsDirectional.fromSTEB(26.rpx, 14, 14, 15),
          height: 120,
          decoration: BoxDecoration(
            color: Color(0XFF003058),
          ),
          child: Column(
            mainAxisSize: MainAxisSize.max,
            children: [
              Padding(
                padding: const EdgeInsetsDirectional.fromSTEB(0, 0, 0, 4),
                child: Container(
                  width: MediaQuery.sizeOf(context).width,
                  // height: MediaQuery.sizeOf(context).height * 0.018,
                  constraints: const BoxConstraints(
                    minHeight: 30,
                  ),

                  child: Container(
                    width: MediaQuery.sizeOf(context).width,
                    height: MediaQuery.sizeOf(context).height * 0.018,
                    child: Align(
                      alignment: const AlignmentDirectional(0, 0),
                      child: Text(
                        // experienceStoreModel.name ?? '未命名',
                        data["name"] ?? '',
                        style: TextStyle(
                          fontFamily: 'Readex Pro',
                          color: Colors.white,
                          fontSize: 30.rpx,
                          letterSpacing: 0,
                        ),
                      ),
                    ),
                  ),
                ),
              ),
              Container(
                width: MediaQuery.sizeOf(context).width,
                height: 1.rpx,
                decoration: const BoxDecoration(
                  color: Color(0xFF929699),
                ),
              ),
              Flexible(
                child: Padding(
                  padding: const EdgeInsetsDirectional.fromSTEB(0, 10, 0, 0),
                  child: Container(
                    width: MediaQuery.sizeOf(context).width,
                    // height: MediaQuery.sizeOf(context).height * 0.034,
                    constraints: const BoxConstraints(
                      minHeight: 55,
                    ),

                    child: Container(
                      width: MediaQuery.sizeOf(context).width,
                      height: MediaQuery.sizeOf(context).height * 0.034,
                      constraints: const BoxConstraints(
                        minHeight: 55,
                      ),
                      child: Column(
                        mainAxisSize: MainAxisSize.max,
                        children: [
                          Flexible(
                            child: Align(
                              alignment: const AlignmentDirectional(-1, 0),
                              child: Text(
                                '地址：${data["addressDetail"]}',
                                style: TextStyle(
                                    fontFamily: 'Readex Pro',
                                    color: const Color(0xFF929699),
                                    fontSize: 20.rpx,
                                    letterSpacing: 0,
                                    height: 1),
                              ),
                            ),
                          ),
                          Flexible(
                            child: Align(
                              alignment: const AlignmentDirectional(-1, 0),
                              child: Text(
                                '电话：${data["hotline"]}',
                                style: TextStyle(
                                    fontFamily: 'Readex Pro',
                                    color: const Color(0xFF929699),
                                    fontSize: 20.rpx,
                                    letterSpacing: 0,
                                    height: 1),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
              Flexible(
                child: Container(
                  width: MediaQuery.sizeOf(context).width,
                  // height: MediaQuery.sizeOf(context).height * 0.038,

                  child: Container(
                    width: MediaQuery.sizeOf(context).width,
                    height: MediaQuery.sizeOf(context).height * 0.038,
                    child: Row(
                      mainAxisSize: MainAxisSize.max,
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: [
                        Flexible(
                            child: InkWell(
                          onTap: () {
                            MyUtils.makePhoneCall("${data["hotline"]}");
                          },
                          child: Container(
                            width: MediaQuery.sizeOf(context).width * 0.105,
                            height: MediaQuery.sizeOf(context).height * 0.038,
                            constraints: const BoxConstraints(
                              minWidth: 50,
                            ),
                            child: Row(
                              mainAxisSize: MainAxisSize.max,
                              children: [
                                Flexible(
                                  // child: Icon(
                                  //   Icons.phone_in_talk,
                                  //   color: Color(0xFFD3B684),
                                  //   size: 12,
                                  // ),
                                  child: SvgPicture.asset(
                                    'assets/images/phone.svg',
                                    width: 27.rpx,
                                    height: 27.rpx,
                                    color: const Color(0xFF84F5FF),
                                  ),
                                ),
                                Text(
                                  '咨询',
                                  style: TextStyle(
                                    fontFamily: 'Readex Pro',
                                    color: Colors.white,
                                    fontSize: AppFontsize.small_text_size,
                                    letterSpacing: 0,
                                  ),
                                ),
                              ].divide(const SizedBox(width: 13)),
                            ),
                          ),
                        )),
                        Flexible(
                          child: InkWell(
                            onTap: () async {
                              //"latitude" -> "31.858934" "longitude" -> "117.282166"
                              AppMapLocation.checkInstalledApps().then((d) {
                                if (AppMapLocation
                                    .availableMapsToNames.isEmpty) {
                                  showToast("未检测到导航软件");
                                } else {
                                  showOneSelectionDialog(context,
                                      title: "选择地图",
                                      arr: AppMapLocation.availableMapsToNames,
                                      checkChange: (index) {
                                    AppMapLocation.launchMap(
                                        index,
                                        data["name"],
                                        double.parse("${data["latitude"]}"),
                                        double.parse("${data["longitude"]}"));
                                  });
                                }
                              });
                            },
                            child: Container(
                              width: MediaQuery.sizeOf(context).width * 0.105,
                              height: MediaQuery.sizeOf(context).height * 0.038,
                              constraints: const BoxConstraints(
                                minWidth: 50,
                              ),
                              child: Row(
                                mainAxisSize: MainAxisSize.max,
                                children: [
                                  Flexible(
                                    // child: Icon(
                                    //   Icons.location_on,
                                    //   color: Color(0xFFD3B684),
                                    //   size: 12,
                                    // ),
                                    child: SvgPicture.asset(
                                      'assets/images/locationColor.svg',
                                      width: 22.rpx,
                                      height: 29.rpx,
                                      color: Color(0xFF84F5FF),
                                    ),
                                  ),
                                  Text(
                                    '导航',
                                    style: TextStyle(
                                      fontFamily: 'Readex Pro',
                                      color: Colors.white,
                                      fontSize: AppFontsize.small_text_size,
                                      letterSpacing: 0,
                                    ),
                                  ),
                                ].divide(const SizedBox(width: 13)),
                              ),
                            ),
                          ),
                        ),
                        Container(
                          width: MediaQuery.sizeOf(context).width * 0.208,
                          height: MediaQuery.sizeOf(context).height * 0.038,
                          constraints: BoxConstraints(
                            maxWidth: 156.rpx,
                            maxHeight: 60.rpx,
                          ),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(30.rpx),
                          ),
                          child: FFButtonWidget(
                            onPressed: () {
                              BookInfoController bookInfoController =
                                  Get.find<BookInfoController>();
                              bookInfoController.model.userName = "";
                              bookInfoController.model.userPhone = "";
                              Get.toNamed("/bookInfoPage",
                                  arguments: {"data": data});
                            },
                            text: '预约',
                            options: FFButtonOptions(
                              padding: const EdgeInsetsDirectional.fromSTEB(
                                  0, 0, 0, 0),
                              color: Color(0xFF84F5FF),
                              textStyle: TextStyle(
                                fontFamily: 'Readex Pro',
                                color: Color(0xFF011D33),
                                fontSize: 26.rpx,
                                letterSpacing: 0,
                              ),
                              elevation: 0,
                              borderSide: const BorderSide(
                                color: Colors.transparent,
                                width: 1,
                              ),
                              borderRadius: BorderRadius.circular(30.rpx),
                            ),
                          ),
                        ),
                      ].divide(const SizedBox(width: 26)),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),

        // ),
      ),
    );
  }
}
