import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vitalapp/components/button.dart';
import 'package:vitalapp/components/side_nav/defines.dart';
import 'package:vitalapp/components/side_nav/side_nav.dart';
import 'package:vitalapp/pages/patient/create/controller.dart';
import 'package:vitalapp/pages/patient/create/widgets/area.dart';
import 'package:vitalapp/pages/patient/create/widgets/crowd_label.dart';
import 'package:vitalapp/pages/patient/create/widgets/patient_info.dart';

class QuickCreatePatientPage extends GetView<CreatePatientController> {
  const QuickCreatePatientPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        VSideNavView(
          // navId: NavIds.CREATE,
          items: _buildItems(),
        ),
        Positioned(
          bottom: 8,
          left: 200,
          right: 200,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              VButton(
                label: "保存",
                onTap: () {
                  controller.gotoPatientDetail();
                },
              ),
            ],
          ),
        ),
      ],
    );
  }

  VSideNavMenuItem _buildCreateManualRecord() {
    return VSideNavMenuItem(
      title: "手动建档",
      icon: Icon(Icons.edit_document, color: Colors.grey.shade700),
      pageBuilder: (_) => _buildInterval(
        PatientInfo(),
      ),
    );
  }

  VSideNavMenuItem _buildIDReaderRecord() {
    return VSideNavMenuItem(
      title: "读卡建档",
      icon: Icon(Icons.chrome_reader_mode, color: Colors.grey.shade700),
      onTap: () {
        controller.onReadCardClicked();
      },
    );
  }

  VSideNavMenuItem _buildScanIdCardRecord() {
    return VSideNavMenuItem(
      title: "身份识别建档",
      icon: Icon(Icons.perm_contact_cal_rounded, color: Colors.grey.shade700),
      onTap: () {
        controller.onIdCardScanClicked();
      },
    );
  }

  VSideNavMenuItem _buildFaceIdLogin() {
    return VSideNavMenuItem(
      title: "人脸识别",
      icon: Icon(Icons.sensor_occupied, color: Colors.grey.shade700),
      onTap: () {
        controller.onFaceIdLoginClicked();
      },
    );
  }

  List<VSideNavMenuItem> _buildItems() {
    final items = <VSideNavMenuItem>[];
    items.add(_buildCreateManualRecord());
    items.add(_buildIDReaderRecord());
    items.add(_buildScanIdCardRecord());
    items.add(_buildFaceIdLogin());
    // items.add(_buildLogOutItem());
    // items.add(_buildSignatureItem());
    // items.add(_buildAboutItem());
    return items;
  }

  VSideNavMenuItem _buildSignatureItem() {
    return VSideNavMenuItem(
      title: "服务信息",
      icon: Icon(Icons.edit_document, color: Colors.grey.shade700),
      pageBuilder: (_) => _buildInterval(
        const Area(),
      ),
    );
  }

  VSideNavMenuItem _buildAboutItem() {
    return VSideNavMenuItem(
      title: "人群分类",
      isRequired: true,
      icon: Icon(Icons.info_outline, color: Colors.grey.shade700),
      pageBuilder: (_) => _buildInterval(
        const CrowdLabelView(),
      ),
    );
  }

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

  Widget _buildInterval(Widget child) {
    return Padding(
      padding: const EdgeInsets.symmetric(
        horizontal: 16,
      ),
      child: child,
    );
  }
}
