import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:terepi_seged/enums/map_survey_mode.dart';
import 'package:terepi_seged/pages/map_survey/presentations/controllers/map_survey_controller.dart';
import 'package:terepi_seged/widgets/gnss_quality_card.dart';
import 'package:terepi_seged/widgets/tracking/track_info_card.dart';
import 'package:terepi_seged/widgets/wgs84_coordinate_card.dart';

import 'eov_coordinate_card.dart';

class MapInfoCardColumn extends StatelessWidget {
  final MapSurveyController controller;

  const MapInfoCardColumn({
    super.key,
    required this.controller,
  });

  @override
  Widget build(BuildContext context) {
    final screenHeight = MediaQuery.sizeOf(context).height;
    final screenWidth = MediaQuery.sizeOf(context).width;

    return Obx(() {
      final cards = <Widget>[];

      if (controller.showWgs84Card.value &&
          controller.mode.value == MapSurveyMode.browse) {
        cards.add(Wgs84CoordinateCard(controller: controller));
      }
      if (controller.showEovCard.value &&
          controller.mode.value == MapSurveyMode.browse) {
        cards.add(EovCoordinateCard(controller: controller));
      }
      if (controller.showGnssQualityCard.value &&
          controller.mode.value == MapSurveyMode.browse) {
        cards.add(GnssQualityCard(controller: controller));
      }

      if (controller.mode.value == MapSurveyMode.track) {
        cards.add(TrackInfoCard());
      }

      if (cards.isEmpty) {
        return const SizedBox.shrink();
      }

      return ConstrainedBox(
          constraints: BoxConstraints(
              minWidth: screenWidth - 50,
              maxWidth: screenWidth - 50,
              maxHeight: screenHeight * 0.55),
          child: SingleChildScrollView(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                for (var i = 0; i < cards.length; i++) ...[
                  cards[i],
                  if (i != cards.length - 1) const SizedBox(height: 4)
                ]
              ],
            ),
          ));
    });
  }
}
