import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vitalapp/architecture/values/features.dart';
import 'package:vitalapp/store/store.dart';

import 'controller.dart';
import 'widgets/base_info.dart';
import 'widgets/functions_panel.dart';
import 'widgets/tag_cards.dart';

class PatientDetailPage extends GetView<PatientDetailController> {
  const PatientDetailPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey.shade200,
      body: Container(
        margin: const EdgeInsets.only(top: 2),
        child: Row(
          children: [
            Container(
              width: 440,
              padding: const EdgeInsets.only(
                left: 12,
                top: 8,
                // right: 8,
                bottom: 8,
              ),
              child: Container(
                padding: const EdgeInsets.only(right: 8),
                child: Column(
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    const BaseInfoCard(),
                    const SizedBox(height: 12),
                    if (Store.user
                        .hasFeature(FeatureKeys.CrowdClassification)) ...[
                      const SizedBox(height: 12),
                      const Expanded(
                        child: CrowdLabelsCard(),
                      ),
                    ],
                    if (Store.user.hasFeature(FeatureKeys.ContractStatus)) ...[
                      const SizedBox(height: 12),
                      const Expanded(child: FollowupTipsCard()),
                    ],
                    if (Store.user.hasFeature(FeatureKeys.RecentTestRecords))
                      FutureBuilder(
                        future: controller.onReadLastRecordInfo(),
                        builder:
                            (BuildContext context, AsyncSnapshot snapshot) {
                          return Expanded(
                            child: LatestRecordCard(
                              connectionState: snapshot.connectionState,
                            ),
                          );
                        },
                      ),
                  ],
                ),
              ),
            ),
            const Expanded(child: FunctionsPanel()),
          ],
        ),
      ),
    );
  }
}
