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

class LabelField extends StatefulWidget {
  final MapSurveyController ctrl;
  const LabelField({required this.ctrl});

  @override
  State<LabelField> createState() => LabelFieldState();
}

class LabelFieldState extends State<LabelField> {
  late final TextEditingController _text;

  @override
  void initState() {
    super.initState();
    _text = TextEditingController(text: widget.ctrl.activeEditLabel.value);
    _text.addListener(() => widget.ctrl.activeEditLabel.value = _text.text);
  }

  @override
  void dispose() {
    _text.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final hint = switch (widget.ctrl.activeEditTool.value) {
      MapEditTool.point => 'Pont neve...',
      MapEditTool.line => 'Vonal neve...',
      MapEditTool.polygon => 'Terület neve...',
      MapEditTool.none => 'Felirat...',
    };
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text('Felirat',
            style: TextStyle(fontSize: 13, color: Colors.grey.shade600)),
        const SizedBox(height: 6),
        TextField(
          controller: _text,
          decoration: InputDecoration(
            hintText: hint,
            filled: true,
            fillColor: Colors.grey.shade100,
            border: OutlineInputBorder(
              borderRadius: BorderRadius.circular(10),
              borderSide: BorderSide.none,
            ),
            contentPadding:
                const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
          ),
        ),
      ],
    );
  }
}
