/*
 * @Descripttion: 
 * @version: 
 * @Author: guanxiaoxin
 * @Date: 2023-09-20 13:29:42
 * @LastEditors: guanxiaoxin
 * @LastEditTime: 2023-10-25 14:26:57
 * @FilePath: \VNoteApp\lib\pages\check\examination\view.dart
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vnoteapp/pages/check/examination/controller.dart';
import 'package:vnoteapp/pages/check/widgets/check_category_widget.dart';
import 'package:vnoteapp/pages/check/widgets/configurable_card.dart';

class ExaminationPage extends GetView<ExaminationController> {
  const ExaminationPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ExaminationController>(
      init: ExaminationController(),
      id: "examination",
      builder: (_) {
        return Scaffold(
          backgroundColor: Colors.white,
          body: Scrollbar(
            thumbVisibility: true,
            child: SingleChildScrollView(
              child: Center(
                child: Container(
                  padding: const EdgeInsets.symmetric(vertical: 20),
                  child: buildExaminationList(),
                ),
              ),
            ),
          ),
        );
      },
    );
  }

  Widget buildExaminationList() {
    return Wrap(
      spacing: 40,
      runSpacing: 40,
      children: controller.menuList
          .map((e) => CheckCategoryWidget(
                label: e.label,
                assetName: "${e.label}.png",
                onTap: () {
                  changePage(e.value);
                },
              ))
          .toList(),
    );
  }

  void changePage(String key) {
    Get.to(
      ConfigurableCard(
        cardKey: key,
        callBack: (key, templateCode, data) async {
          await controller.createExam(key, templateCode, data);
          Get.back();
        },
        patientCode: controller.patientCode,
      ),
      transition: Transition.rightToLeft,
    );
  }
}
