import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:taafee_mobile/common/extensions/widget_extension.dart';
import 'package:taafee_mobile/common/widgets/button.dart';
import 'package:taafee_mobile/common/widgets/text.dart';
import 'package:taafee_mobile/core/routing/routing_manager.dart';
import 'package:taafee_mobile/features/account/business_logic_layer/account_controller.dart';

import '../../../../common/const/const.dart';
import '../../../../common/widgets/header_screen.dart';
import '../../../../common/widgets/textfiled.dart';
import '../../../../common/widgets/toast.dart';

class ContactUsScreen extends StatelessWidget {
  ContactUsScreen({super.key});
  final AccountController accountController = Get.find<AccountController>();
  final GlobalKey<FormState> formKey = GlobalKey<FormState>();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Form(
          key: formKey,
          child: Column(
            children: [
              HeaderScreen("contact_us".tr).paddingOnly(top: 30, bottom: 50),
              MediumTextWidget(
                "contact_us_content".tr,
                fontSize: Responsive.isTablet() ? 24 : null,
              ),
              TextFieldWidget(
                maxLines: 5,
                height: 125,
                onChange: (value) {
                  accountController.feedbackMessageModel.message = value;
                },
                keyboardType: TextInputType.multiline,
                label: "your_message".tr,
                validate: (value) {
                  if (value == null || value == '') {
                    return 'please_enter_your_message'.tr;
                  }
                  return null;
                },
              ).paddingSymmetric(vertical: 15),
              Obx(() {
                return ButtonWidget(
                        isLoading: accountController.sendFeedbackState.loading,
                        onTap: () {
                          if (formKey.currentState!.validate()) {
                            accountController.sendFeedback(onError: (error) {
                              if (error.toString() ==
                                  "You Have no Internet Connection") {
                                Toast.showToast(
                                    "you_have_no_internet_connection".tr);
                              } else {
                                Toast.showToast('unknown_error'.tr);
                              }
                            }, onSuccess: (value) {
                              RoutingManager.back();
                            });
                          }
                        },
                        title: "send_message".tr)
                    .paddingSymmetric(vertical: 30);
              })
            ],
          ).paddingSymmetric(horizontal: 30),
        ),
      ),
    ).makeSafeArea();
  }
}
