import 'package:get/get.dart'; import 'package:marco/helpers/services/api_service.dart'; import 'package:marco/helpers/services/app_logger.dart'; import 'package:marco/helpers/widgets/my_snackbar.dart'; import 'package:marco/controller/directory/directory_controller.dart'; class AddCommentController extends GetxController { final String contactId; AddCommentController({required this.contactId}); final RxString note = ''.obs; final RxBool isSubmitting = false.obs; Future submitComment() async { if (note.value.trim().isEmpty) { showAppSnackbar( title: "Missing Comment", message: "Please enter a comment before submitting.", type: SnackbarType.warning, ); return; } isSubmitting.value = true; try { logSafe("Submitting comment for contactId: $contactId"); final success = await ApiService.addContactComment( note.value.trim(), contactId, ); if (success) { logSafe("Comment added successfully."); // Refresh UI final directoryController = Get.find(); await directoryController.fetchCommentsForContact(contactId); Get.back(result: true); showAppSnackbar( title: "Comment Added", message: "Your comment has been successfully added.", type: SnackbarType.success, ); } else { logSafe("Comment submission failed", level: LogLevel.error); showAppSnackbar( title: "Submission Failed", message: "Unable to add the comment. Please try again later.", type: SnackbarType.error, ); } } catch (e) { logSafe("Error while submitting comment: $e", level: LogLevel.error); showAppSnackbar( title: "Unexpected Error", message: "Something went wrong while adding your comment.", type: SnackbarType.error, ); } finally { isSubmitting.value = false; } } void updateNote(String value) { note.value = value; logSafe("Note updated: ${value.trim()}"); } }