import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:loader_overlay/loader_overlay.dart';

import '../../../app.dart';

class CouponCodeTextFormField extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetX<CartController>(
      init: CartController(),
      builder: (cc) => LoaderOverlay(
        useDefaultLoading: false,
        overlayColor: Colors.transparent,
        overlayWidget: CustomLoader(),
        child: Container(
          padding: const EdgeInsets.only(left: 18),
          height: 55,
          decoration: new BoxDecoration(
            borderRadius: BorderRadius.circular(8),
            border: Border.all(
              color: ThemeColor.grey.withOpacity(0.40),
            ),
          ),
          child: Row(
            children: [
              Expanded(
                child: TextFormField(
                  controller: cc.state.couponCodeCtrl,
                  cursorColor: ThemeColor.cursorColor,
                  textInputAction: TextInputAction.done,
                  decoration: inputDecoration(),
                ),
              ),
              SizedBox(width: 16),
              cc.state.cartModel.value!.couponCode != null
                  ? GestureDetector(
                      onTap: () {
                        KeyboardUtil.hideKeyboard(context);
                        debugPrint('deleteCoupon');
                        cc.deleteCoupon(context);
                      },
                      child: Container(
                        width: 50.w,
                        height: double.infinity,
                        child: Icon(Icons.remove_circle_outline_rounded, color: Color(0xFFC4C4C4)),
                      ),
                    )
                  : GestureDetector(
                      onTap: () {
                        KeyboardUtil.hideKeyboard(context);
                        debugPrint('sen code tapped ${cc.state.couponCodeCtrl}');
                        cc.applyCoupon(context);
                      },
                      child: Container(
                        width: 50.w,
                        height: double.infinity,
                        child: Icon(Icons.send_rounded, color: Color(0xFFC4C4C4)),
                      ),
                    ),
            ],
          ),
        ),
      ),
    );
  }

  InputDecoration inputDecoration() {
    final txtStyle = new TextStyle(
      color: ThemeColor.black.withOpacity(0.60),
      fontSize: 14.sp,
    );
    return InputDecoration(
      isDense: true,
      prefixStyle: txtStyle,
      hintText: 'enter_coupon_code'.tr,
      hintStyle: txtStyle,
      // suffixIcon: Icon(Icons.abc),
      // suffixIconConstraints: BoxConstraints(),
      border: InputBorder.none,
      focusedBorder: InputBorder.none,
      enabledBorder: InputBorder.none,
      disabledBorder: InputBorder.none,
    );
  }
}
