import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vnoteapp/components/appbar.dart';
import 'package:vnoteapp/components/button.dart';
import 'package:vnoteapp/components/side_nav/defines.dart';
import 'package:vnoteapp/components/side_nav/side_nav.dart';
import 'package:vnoteapp/pages/contract/package_list/widgets/capture_portrait.dart';
import 'package:vnoteapp/pages/contract/package_list/widgets/family_doctor_service_package.dart';
import 'package:vnoteapp/pages/contract/package_list/widgets/personal_information.dart';
import 'package:vnoteapp/pages/contract/package_list/widgets/service_information.dart';
import 'package:vnoteapp/routes/nav_ids.dart';
import 'package:vnoteapp/routes/route_setting.dart';
import 'controller.dart';

class ServicePackageContractPage
    extends GetView<ServicePackageContractController> {
  const ServicePackageContractPage({super.key});
  static const double labelSize = 20;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: VAppBar(
        titleWidget: const Text(
          "签约",
          style: TextStyle(fontSize: 24),
        ),
      ),
      body: Stack(
        children: [
          VSideNavView(
            navId: NavIds.CONTRACT,
            items: _buildItems(),
          ),
          Positioned(
            bottom: 8,
            left: 200,
            right: 200,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                VButton(
                  label: "下一步",
                  onTap: () {
                    Get.back();
                    Get.toNamed(
                      "/contract/contract_template",
                      parameters: {
                        "templateCode": "53C3323BB6444A109B2369703EFFDFF9",
                        "patientInfo": json.encode(controller.patient.toJson()),
                        "servicePackageCodes":
                            controller.state.selectedServicePackageCode,
                        "servicePackageNames":
                            controller.state.selectedServicePackageName,
                        "serviceTime": controller.state.serviceTime.toString(),
                        "serviceStartDate":
                            controller.state.serviceStartDate.toString(),
                        "base64Image": controller.base64Image,
                        "notes": controller.state.notes,
                      },
                    );
                  },
                ),
              ],
            ),
          ),
          // const FloatingWindow(),
        ],
      ),
    );
  }

  List<VSideNavMenuItem> _buildItems() {
    final items = <VSideNavMenuItem>[];
    items.add(_buildCapturePortrait());
    items.add(_buildPersonalInformation());
    items.add(_buildServiceInformation());
    items.add(_buildFamilyDoctorServicePackage());

    return items;
  }

  VSideNavMenuItem _buildCapturePortrait() {
    return VSideNavMenuItem(
      title: "人像采集",
      icon: Icon(Icons.edit_document, color: Colors.grey.shade700),
      // onTap: () {}
      route: VRouteSetting(
        "/capture_portrait_page",
        () => const CapturePortraitPage(),
        binding: BindingsBuilder(
          () {
            Get.lazyPut(() => ServicePackageContractController());
          },
        ),
      ),
    );
  }

  VSideNavMenuItem _buildServiceInformation() {
    return VSideNavMenuItem(
      title: "服务信息",
      icon: Icon(Icons.edit_document, color: Colors.grey.shade700),
      // onTap: () {}
      route: VRouteSetting(
        "/service_information_page",
        () => const ServiceInformationPage(),
        binding: BindingsBuilder(
          () {
            Get.lazyPut(() => ServicePackageContractController());
          },
        ),
      ),
    );
  }

  VSideNavMenuItem _buildFamilyDoctorServicePackage() {
    return VSideNavMenuItem(
      title: "家庭医生服务包",
      icon: Icon(Icons.edit_document, color: Colors.grey.shade700),
      // onTap: () {}
      route: VRouteSetting(
        "/family_doctor_service_package_page",
        () => const FamilyDoctorServicePackagePage(),
        binding: BindingsBuilder(
          () {
            Get.lazyPut(() => ServicePackageContractController());
          },
        ),
      ),
    );
  }

  VSideNavMenuItem _buildPersonalInformation() {
    return VSideNavMenuItem(
      title: "个人信息",
      icon: Icon(Icons.edit_document, color: Colors.grey.shade700),
      // onTap: () {}
      route: VRouteSetting(
        "/personal_information_page",
        () => const PersonalInformationPage(),
        binding: BindingsBuilder(
          () {
            Get.lazyPut(() => ServicePackageContractController());
          },
        ),
      ),
    );
  }

  // VSideNavMenuItem _buildAboutItem() {
  //   return VSideNavMenuItem(
  //     title: "人群分类",
  //     isRequired: true,
  //     icon: Icon(Icons.info_outline, color: Colors.grey.shade700),
  //     route: VRouteSetting(
  //       "/crowd_label_panel",
  //       () => CrowdLabel(),
  //       binding: BindingsBuilder(
  //         () {
  //           Get.lazyPut(() => CrowdLabelsController());
  //           Get.lazyPut(() => CreatePatientController());
  //         },
  //       ),
  //     ),
  //     // route: VRouteSetting("/about", () => const AboutPage()),
  //   );
  // }

  // VSideNavMenuItem _buildLogOutItem() {
  //   return VSideNavMenuItem(
  //     title: "个人信息",
  //     icon: Icon(Icons.exit_to_app, color: Colors.grey.shade700),
  //     route: VRouteSetting(
  //       "/patient_info_panel",
  //       () => const PatientInfo(),
  //       binding: BindingsBuilder(
  //         () {
  //           Get.lazyPut(() => CreatePatientController());
  //         },
  //       ),
  //     ),
  //     // shouldRearrage: true, // TODO: 调整样式后启用
  //   );
  // }
}
