import "package:client/widgets.dart";
import "package:flutter/material.dart";

class LatLongEditor extends StatelessWidget {
  final TextEditingController latitudeController;
  final TextEditingController longitudeController;
  final String label;
  final VoidCallback showMarkers;
  final VoidCallback hideMarkers;
  final bool isShowingMarkers;

  const LatLongEditor({
    required this.latitudeController,
    required this.longitudeController,
    required this.label,
    required this.isShowingMarkers,
    required this.showMarkers,
    required this.hideMarkers,
    super.key,
  });

  @override
  Widget build(BuildContext context) => SizedBox(
    width: 400,
    child: Row(
      children: [
        Text(label, style: context.textTheme.titleSmall),
        const SizedBox(width: 8),
        Expanded(
          child: TextField(
            controller: latitudeController,
            decoration: const InputDecoration(
              hintText: "Latitude",
              border: OutlineInputBorder(),
            ),
          ),
        ),
        const SizedBox(width: 8),
        Expanded(
          child: TextField(
            controller: longitudeController,
            decoration: const InputDecoration(
              hintText: "Longitude",
              border: OutlineInputBorder(),
            ),
          ),
        ),
        const SizedBox(width: 8),
        if (isShowingMarkers) TextButton(
          onPressed: hideMarkers,
          child: const Text("Cancel"),
        ) else TextButton.icon(
          icon: const Icon(Icons.location_on),
          onPressed: showMarkers,
          label: const Text("Pick on map"),
        ),
      ],
    ),
  );
}
