import 'package:fis_jsonrpc/rpc.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vitalapp/pages/check/follow_up/widgets/follow_up_from.dart';
import 'package:vitalapp/pages/check/widgets/check_category_widget.dart';
import 'package:vitalapp/pages/check/widgets/configurable_card.dart';

import 'index.dart';

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

  @override
  Widget build(BuildContext context) {
    return GetBuilder<FollowUpController>(
      init: FollowUpController(),
      id: "examination",
      builder: (_) => buildFollowUpPage(),
    );
  }

  Widget buildFollowUpPage() {
    return Scaffold(
      backgroundColor: const Color.fromRGBO(238, 238, 238, 1),
      // appBar: VAppBar(
      //   titleWidget: const Text('人群随访'),
      // ),
      body: Scrollbar(
        thumbVisibility: true,
        child: SingleChildScrollView(
          child: Container(
            padding: const EdgeInsets.symmetric(
              horizontal: 20,
              vertical: 20,
            ),
            child: buildFollowUpList(),
          ),
        ),
      ),
    );
  }

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

  void changePage(String key) {
    controller.state.followUpTime = DateTime.now();
    controller.state.nextFollowUpTime = null;
    controller.state.followUpMode = FollowUpModeEnum.Outpatient;
    controller.state.followUpPhoto = '';
    Get.to(
      ConfigurableCard(
        cardKey: key,
        callBack: (key, templateCode, data) async {
          await controller.createFollowUp(key, templateCode, data);

          Get.back();
        },
        followUpWidget: const FollowUpFrom(),
      ),
      transition: Transition.rightToLeft,
    );
  }
}
