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 CreatePatientPage extends GetView<CreatePatientController> {
  const CreatePatientPage({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();
                },
              ),
            ],
          ),
        ),
      ],
    );
  }

  List<VSideNavMenuItem> _buildItems() {
    final items = <VSideNavMenuItem>[];
    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(
        const 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,
    );
  }
}
