import 'package:flutter/material.dart';
import 'package:terepi_seged/controls/wgs84_coordinate_formatter.dart';
import 'package:terepi_seged/pages/map_survey/presentations/controllers/map_survey_controller.dart';

class FormatMenuButton extends StatelessWidget {
  final MapSurveyController controller;

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

  @override
  Widget build(BuildContext context) {
    return PopupMenuButton<Wgs84CoordinateFormat>(
      tooltip: 'Koordinátaformátum',
      initialValue: controller.wgs84CoordinateFormat.value,
      onSelected: controller.setWgs84CoordinateFormat,
      itemBuilder: (context) {
        return Wgs84CoordinateFormat.values.map((format) {
          return CheckedPopupMenuItem<Wgs84CoordinateFormat>(
            value: format,
            checked: controller.wgs84CoordinateFormat.value == format,
            child: Text(format.label),
          );
        }).toList();
      },
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 4),
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text(
              controller.wgs84CoordinateFormat.value.shortLabel,
              style: Theme.of(context).textTheme.labelMedium?.copyWith(
                    fontWeight: FontWeight.w700,
                  ),
            ),
            const Icon(Icons.arrow_drop_down, size: 18),
          ],
        ),
      ),
    );
  }
}
