import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:terepi_seged/pages/map_survey/presentations/controllers/map_survey_controller.dart';
import 'package:terepi_seged/services/gnss/gnss_connection.dart';
import 'package:terepi_seged/services/gnss/gnss_device_service.dart';
import 'package:terepi_seged/services/gnss/gnss_service.dart';

import 'map_edit_small_status_chip.dart';

class PointDrawingContent extends StatelessWidget {
  final MapSurveyController controller;

  const PointDrawingContent({
    required this.controller,
  });

  @override
  Widget build(BuildContext context) {
    final colorScheme = Theme.of(context).colorScheme;

    return Obx(() {
      // final hasPoint = controller.draftPoints.isNotEmpty;
      //final hasPoint = true;
      final isEditing = controller.isGeometryEditing;

      return Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Row(
            children: [
              Icon(
                controller.activeEditToolIcon,
                size: 20,
                color: colorScheme.primary,
              ),
              const SizedBox(width: 8),
              Expanded(
                child: Text(
                  isEditing
                      ? 'Pont szerkesztése'
                      : controller.activeEditToolTitle,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: Theme.of(context).textTheme.titleSmall?.copyWith(
                        fontWeight: FontWeight.w800,
                      ),
                ),
              ),
              SmallStatusChip(
                text: '1 pont',
                color: colorScheme.primary,
              ),
            ],
          ),
          const SizedBox(height: 5),
          Align(
            alignment: Alignment.centerLeft,
            child: Text(
              isEditing
                  ? 'Hosszan nyomj a térképen az új helyre.'
                  : controller.activeEditToolHint,
              maxLines: 2,
              overflow: TextOverflow.ellipsis,
              style: Theme.of(context).textTheme.bodySmall?.copyWith(
                    color: colorScheme.onSurfaceVariant,
                    height: 1.15,
                  ),
            ),
          ),
          const SizedBox(height: 8),
          Row(
            children: [
              Expanded(
                child: OutlinedButton.icon(
                  onPressed: controller.cancelEditing,
                  icon: const Icon(Icons.close, size: 18),
                  label: const Text('Mégse'),
                ),
              ),
              const SizedBox(width: 8),
              Expanded(
                child: OutlinedButton.icon(
                  //onPressed: controller.addPointFromCurrentPosition,
                  onPressed: GnssService.to.connectionState.value ==
                          GnssConnectionState.connected
                      ? controller.savePointFromCurrentPosition
                      : null,
                  icon: const Icon(Icons.my_location, size: 18),
                  label: const Text('Saját hely'),
                ),
              ),
              // const SizedBox(width: 8),
              // Expanded(
              //   child: FilledButton.icon(
              //     // onPressed: controller.canFinishGeometry
              //     //     ? controller.finishGeometry
              //     //     : null,
              //     onPressed: () {},
              //     icon: const Icon(Icons.check, size: 18),
              //     label: const Text('Kész'),
              //   ),
              // ),
            ],
          ),
        ],
      );
    });
  }
}
