import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:location/base/base_page.dart';
import 'package:location/resource/string.gen.dart';
import 'package:location/utils/common_expand.dart';
import '../../resource/colors.gen.dart';
import '../../router/app_pages.dart';
import '../../widget/common_view.dart';
import 'feed_back_controller.dart';

class FeedBackPage extends BasePage<FeedBackController> {
  const FeedBackPage({super.key});

  static void start() {
    Get.toNamed(RoutePath.feedback);
  }

  @override
  Widget buildBody(BuildContext context) {
    return Stack(
      children: [
        GestureDetector(
          onTap: () => FocusScope.of(Get.context!).unfocus(),
          child: Container(
            color: Colors.white,
          ),
        ),
        Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            CommonView.buildAppBar(StringName.feedBack,
                backOnTap: controller.back, titleCenter: false),
            SizedBox(height: 12.w),
            Align(
              alignment: Alignment.centerLeft,
              child: Padding(
                padding: EdgeInsets.only(left: 14.w),
                child: Text(StringName.feedBackTitle,
                    style: TextStyle(fontSize: 14.sp, color: '#202020'.color)),
              ),
            ),
            SizedBox(height: 12.w),
            buildFeedbackPrintView(),
            Spacer(),
            GestureDetector(
              onTap: controller.submit,
              child: Container(
                width: 240.w,
                height: 50.w,
                decoration: BoxDecoration(
                  color: ColorName.colorPrimary,
                  borderRadius: BorderRadius.circular(100.w),
                ),
                child: Center(
                  child: Text(StringName.feedBackSubmitTxt,
                      style: TextStyle(fontSize: 16.sp, color: ColorName.white)),
                ),
              ),
            ),
            SizedBox(height: 24.w),
            GestureDetector(
              onTap: controller.onCustomerServiceClick,
              child: Text(StringName.feedBackCustomerService,
                  style: TextStyle(
                      decoration: TextDecoration.underline,
                      fontSize: 14.sp,
                      color: ColorName.black)),
            ),
          ],
        )
      ],
    );
  }

  Widget buildFeedbackPrintView() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 12.w),
      height: 270.h,
      decoration: BoxDecoration(
        color: '#FAFAFA'.color,
        borderRadius: BorderRadius.circular(6.w),
      ),
      child: Stack(children: [
        TextField(
          keyboardType: TextInputType.multiline,
          maxLength: 500,
          maxLines: null,
          minLines: 12,
          style: TextStyle(fontSize: 14.sp, color: ColorName.primaryTextColor),
          decoration: InputDecoration(
            counterText: "",
            border: InputBorder.none,
            fillColor: Colors.transparent,
            hintText: StringName.feedBackHint,
            hintStyle: TextStyle(fontSize: 14.sp, color: '#A7A7A7'.color),
            contentPadding: EdgeInsets.only(
                left: 12.w, right: 12.w, top: 12.w, bottom: 28.w),
          ),
          onChanged: (value) {
            controller.content = value;
          },
          scrollPhysics: ClampingScrollPhysics(),
        ),
        Obx(() {
          return Positioned(
            bottom: 10.w,
            right: 12.w,
            child: Text('${controller.content.length}/500',
                style: TextStyle(fontSize: 14.sp, color: '#A7A7A7'.color)),
          );
        })
      ]),
    );
  }
}
