import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vitalapp/architecture/values/features.dart';
import 'package:vitalapp/consts/styles.dart';
import 'package:vitalapp/pages/widgets/function_button.dart';
import 'package:vitalapp/store/store.dart';

import '../controller.dart';

/// 功能入口面板
class FunctionsPanel extends GetView<PatientDetailController> {
  const FunctionsPanel({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.topLeft,
      margin: const EdgeInsets.all(8).copyWith(left: 0, right: 12),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: GlobalStyles.borderRadius,
      ),
      padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 10)
          .copyWith(right: 0),
      child: GridView(
        padding: const EdgeInsets.symmetric(horizontal: 32).copyWith(top: 12),
        // shrinkWrap: true,
        // controller: scrollController,
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 3,
          mainAxisSpacing: 24,
          crossAxisSpacing: 24,
          childAspectRatio: 15 / 14,
        ),
        children: [
          if (Store.user.hasFeature(FeatureKeys.HealthRecordHandling))
            FunctionButton(
              label: "健康档案",
              icon: _buildImgIcon("档案.png"),
              onTap: controller.gotoInfo,
            ),
          // FunctionButton(
          //   label: "体检记录",
          //   icon: _buildImgIcon("体检记录.png"),
          //   onTap: controller.gotoHealthCheckRecord,
          // ),
          // FunctionButton(
          //   label: "随访记录",
          //   icon: _buildImgIcon("随访报告.png"),
          //   onTap: controller.gotoFollowUpRecord,
          // ),
          // FunctionButton(
          //   label: "双向转诊",
          //   icon: _buildImgIcon("转诊.png"),
          //   onTap: controller.gotoReferral,
          // ),
          // FunctionButton(
          //   label: "签约记录",
          //   icon: _buildImgIcon("签约记录.png"),
          //   onTap: controller.gotoContractRecords,
          // ),
          if (Store.user.hasFeature(FeatureKeys.HealthCheckupRecords))
            FunctionButton(
              label: "健康检测记录",
              icon: _buildImgIcon("诊疗.png"),
              onTap: controller.gotoExamRecord,
            ),
        ],
      ),
    );
  }

  Widget _buildImgIcon(String assetName) {
    return Image.asset(
      "assets/images/patient/$assetName",
      width: 120,
      height: 120,
      fit: BoxFit.contain,
    );
  }
}
